Thread: [BUGS] BUG #14688: Wrong results in LIKE operation on JSON Type
The following bug has been logged on the website: Bug reference: 14688 Logged by: Ilya Kopylov Email address: nblxa@mail.ru PostgreSQL version: 9.6.0 Operating system: Windows 8.1 Description: When JSON contains '\\' symbol, then operator '=' works well, but operator 'LIKE' return wrong result. SELECT '{"Name":"Domen\\Ivan"}'::json ->> 'Name' = 'Domen\Ivan'; -- yields true SELECT '{"Name":"Domen\\Ivan"}'::json ->> 'Name' LIKE 'Domen\Ivan'; -- yields false SELECT '{"Name":"Domen\\Ivan"}'::json ->> 'Name' LIKE 'Domen\\Ivan'; -- yields true When I search with 'LIKE' operator and adding '\' symbol, when got result. I think whis is bug. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
nblxa@mail.ru writes: > When JSON contains '\\' symbol, then operator '=' works well, but operator > 'LIKE' return wrong result. > SELECT '{"Name":"Domen\\Ivan"}'::json ->> 'Name' = 'Domen\Ivan'; -- yields > true > SELECT '{"Name":"Domen\\Ivan"}'::json ->> 'Name' LIKE 'Domen\Ivan'; -- > yields false > SELECT '{"Name":"Domen\\Ivan"}'::json ->> 'Name' LIKE 'Domen\\Ivan'; -- > yields true I think you've forgotten that backslash is an escape character in LIKE patterns. You could use ... LIKE 'Domen\Ivan' ESCAPE '' if you don't want that behavior. https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-LIKE regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs