Answer the question
In order to leave comments, you need to log in
Why doesn't backslash work in a database?
UPDATE `test` SET answer = '{"test":["qwerty","\"test\""]}' - with this query, if the data type of the column is TEXT, then the string is stored: {"test":[" qwerty",""test""]} - (without backslash) and such json becomes invalid. If the data type of the column is JSON, then it simply throws an error, as if the error was in JSON. As a result, saving the string - "test" (instead of with quotes) does not work. I will be glad to answer
Answer the question
In order to leave comments, you need to log in
Because with your code you are telling the SQL parser to "treat the character after the \ as plain text".
PS Moreover, according to all SQL rules, you must escape all characters with a backslash \ in general " ' \
to avoid hacking through SQL injections:
UPDATE `test` SET answer = '{\"test\":[\"qwerty\",\"\\\"test\\\"\",\"-\'-\"]}'
You need to escape the slash:
update `test` set `answer` = '{"test":["qwerty","\\"test\\""]}' ;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question