Fork me on GitHub
quan xing07:08:45

I use mysql8 + next.jdbc the one of the cloumn type is JSON. In mysql client use update command update JSON is OK , but my programm execute update sql show error:

com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Invalid JSON text: "Invalid encoding in string." at position 843 in value for column 'bz_unit_certificate_ui.performance'.
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(
        at com.mysql.cj.jdbc.ClientPreparedStatement.execute(
        at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(

        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(
        at next.jdbc.result_set$stmt__GT_result_set.invokeStatic(result_set.clj:650)
        at next.jdbc.result_set$stmt__GT_result_set.invoke(result_set.clj:645)
        at next.jdbc.result_set$eval9716$fn__9724.invoke(result_set.clj:925)
        at next.jdbc.protocols$eval8798$fn__8799$G__8789__8808.invoke(protocols.clj:33)
        at next.jdbc$execute_BANG_.invokeStatic(jdbc.clj:250)
        at next.jdbc$execute_BANG_.invoke(jdbc.clj:237)
        at clojure.lang.AFn.applyToHelper(
        at clojure.lang.AFn.applyTo(
        at clojure.spec.test.alpha$spec_checking_fn$fn__3023.doInvoke(alpha.clj:153)
I copy SQL use #dbg from var and run it in mysql is ok. The SQL not have a gramma question.


Character encoding issue


Make sure everything is utf8, and your database columns in MySQL are utf8mb4

quan xing07:08:37

How can I encoding it I copy SQL from memory and run it in mysql client is ok


Because the act of printing it out and copy and pasting it can change the encoding

quan xing07:08:21

Yes I found it in JSON from memory

quan xing10:08:33

I use clojure.string/replace '\\n' to '\\\n' or replace '\\n' to '\n' It's still get a error

(s/replace (first sql) #"\\n" "\\n")
==> Data truncation: Invalid JSON text: "Invalid encoding in string." if I repalce "\\n" to ";" (other chacter) is successed. How can I escape the "\\n"

Jim Newton09:08:14

can someone help me remember the function names to find prefixes and suffixes of a sequence? e.g. given a list of length n, there's a function that given 5 will find the tail/suffix of the list starting at element number 5. (rest^5 some-seq)

Jim Newton09:08:39

no, i want to effectively call rest 5 times, finding the 5th tail. in common-lisp it is called nth-cdr


I think it's just drop



✔️ 1
Jim Newton09:08:33

it is amazing how many small things I forget, not using the language for a while. I was searching for nth-rest and rest-n, and nth-suffix, etc...


nthrest works too


but drop is better if you don't need to eagerly eval the dropped items

delaguardo09:08:54 is amazing for lookup something you forget about. you probably remember rest and for this function on clojuredocs there is See Also section with other functions with similar or connected behaviour.

Jim Newton09:08:06

its for a test case so I don't care about laziness. ahh nthrest, not nth-rest. voilà

Jim Newton09:08:50

thanks delaguardo, I did indeed glance quickly through the doc of rest, mostly at the examples, while also searching for prefix, suffix, etc. didn't get all the way to the see-also section.

Jim Newton09:08:41

does the search field in clojuredocs search only function names, or does it search the text as well? its notable that the doc for nthrest does not contain the word "suffix"

Jim Newton09:08:18

neither does the doc for drop.


maybe its due to drop being lazy and suffix could imply eagerness?

Jim Newton09:08:58

naaaa, lazy suffix is quite easy to understand.


@U010VP3UY9X search field on clojuredocs is only for function name. but See Also section does contain docstrings for other functions as well. 1. you wanted a function with some extended behaviour for the rest function 2. lookup rest on clojuredocs, that will give you this page - 3. Inside of See Also right after examples there are links to drop , nthrest , nthnext 4. and for drop the docstring say “Returns a lazy sequence of all but the first n items in coll.” which sounds to me exactly as you describe what you was looking for. Clojure has it own “standard library” which doesn’t have to be similar to anything you previously had to deal with. This is why there is no mention of “suffix” anywhere.

Jim Newton09:08:41

would be nice if the search, also searched the content (or optionally so). That way someone (anyone) could just add a helpful example containing the word suffix, and problem solved. It is nice that clojuredocs already alows users to add helpful examples.

Jim Newton09:08:49

for example, in the reduce doc there's a helpful example which reminds me of the order of the arguments to the client function [acc item] rather than [item acc] . I use that example often actually.

Alex Miller (Clojure team)12:08:06

clojure.repl/find-docs searches docstrings (and can take a regex)


You might try Find the right section, in this case “Seq in, Seq out “, then explore Tail-items rest nthrest next fnext nnext drop drop-while take-last for


How would I output an input-stream into a file? I tried this

(defn input-stream->file [input-stream file-path]
  (with-open [o (io/output-stream file-path)]
    (.write o input-stream)))
but receive an error


also the error could be due the input-stream not being open?


Given a long string and a set of subs ranges, how can I return a new string with upper-case applied to each of the given ranges? Is there something that can help with this kind of string transformation or just reduce over it with subs?

Daniel Craig17:08:40

(let [long-string "The rain in spain falls mainly on the plains"
        ranges #{[5 8] [5 15] [2 5]}]
    (mapv (comp clojure.string/upper-case (partial apply subs long-string)) ranges))
This could be an approach? perhaps it could be more readable


repeated uses of str will murder performance. You’ll really need a StringBuilder


Maybe something like this?:

(let [to-uppercase? (fn [n uppercase-ranges] (some #(some #{n} (apply range %)) uppercase-ranges))]
  (->> "Aliquam erat volutpat. Nunc eleifend leo vitae magna. In id erat non orci commodo lobortis. Proin neque massa, cursus ut, gravida ut, lobortis eget, lacus."
       (map-indexed (fn [idx char]
                      (if (to-uppercase? idx #{[0 7] [13 21]})
                        (Character/toUpperCase char)
       (apply str)))
Although it is linear, so it would be slow for really long strings.


The strings I'm dealing with are quite long, so efficiency is definitely a consideration.


You might look into a rope datastructure that can handle changes in the string without continually rebuilding the entire string

👀 2

I'm a little surprised this isn't part of one of the string manipulation libraries like or


profile it against a reduce. but in general a rope should be better. But who knows with the immutability. Maybe finding a mutable one or perhaps that offers a transient version?


Noted.. will do. Thanks everyone for the input.


any rule of thumb for when a dev should think of this type of issue (performance of strings)