I have mssql query which works to query the json data which kept in database column like below:
SELECT COUNT(*) as count FROM t1.test where lower(data) LIKE '%state':'new%'
{
"id": "DO-Test CC1",
"state": "NEW",
"type": "Test type",
"items": [
{
"itemReports": [],
"id": "066c7499-a4b6-4346-ac98-6a71d0ddfc36",
"itemId": "Augmentn New",
"quantity": 100,
"dispenseAsWritten": false,
"administrationInstructions": "123"
}
]
}
It does not work when i run it at pgAdmin (postgres database).
i am using Docker version 19.03.4, build 9013bf5
which syntax should be replaced?
'%state':'new%'that won't work because (a) json elements won't be single quoted, and (b) you've got 2 strings there separate by a colon which is not part of those strings, so I'd expect pg to raise an exception. You're looking for'%"state":"new"%', but of course you really should be using the json operator as in the answers below.