Re: BUG #14688: Wrong results in LIKE operation on JSON Type

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: nblxa(at)mail(dot)ru
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14688: Wrong results in LIKE operation on JSON Type
Date: 2017-06-05 14:01:45
Message-ID: 32396.1496671305@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

nblxa(at)mail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Joe Conway 2017-06-05 14:20:46 Re: BUG #14682: row level security not work with partitioned table
Previous Message gdutton 2017-06-05 13:09:54 BUG #14690: Client GSSAPI / Kerberos auth crash