In the database, there is a field that stores JSON, and the content is roughly as follows:
"content":{"systemToken":false,"timezone":"America/Los_Angeles","totalCount":false,"userIds":[]}"
The requirement is to query data where totalCount is true.
SELECT * from task where column_a like '%"totalCount%'
This query returns results, but when additional characters are added to the end, there are no results returned.
SELECT * from task where column_a like '%"totalCount"%'
How should the SQL be written when there are double quotes (") and backslashes () in the LIKE statement?
2
Answers
Maybe this will help
SELECT * FROM task WHERE column_a LIKE '%"totalCount":true%'
The backslash is an escape character in
LIKE
patterns, so you either have to double the backslashes:or specify that you want no escape character:
See the documentation for details.