Re: BUG #14512: Backslashes in LIKE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Alex Malek <magicagent(at)gmail(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14512: Backslashes in LIKE
Date: 2017-03-17 20:04:45
Message-ID: 28169.1489781085@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Fri, Mar 17, 2017 at 11:16 AM, Alex Malek <magicagent(at)gmail(dot)com> wrote:
>> Given the current behavior the same query will work or raise on error
>> based on context.

> Recently discussed here:
> https://www.postgresql.org/message-id/flat/20170124172505(dot)1431(dot)56735%40wrigleys(dot)postgresql(dot)org#20170124172505(dot)1431(dot)56735(at)wrigleys(dot)postgresql(dot)org
> In short - preventing a "fails-to-fail" scenario here doesn't seem worthy
> of the effort and run-time cost doing so would entail.

BTW, looking again at the patch I suggested in
https://www.postgresql.org/message-id/10287.1485286334%40sss.pgh.pa.us
it strikes me that the check logic was unnecessarily stupid. What
we need to check is that there's not an odd number of backslashes at
the end of the pattern. Since we know that backend encodings are
ASCII-safe, the test logic could be changed to scan backwards,
something like

p += plen;
nbackslash = 0;
while (plen-- > 0)
{
if (*(--p) == '\\')
nbackslash++;
else
break;
}
if (nbackslash & 1)
ereport(ERROR, ...);

For patterns of practical interest this would be of small and nearly
constant cost. Maybe it is worth doing, especially since we've now
had two independent complaints about it.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Masahiko Sawada 2017-03-17 22:01:31 Re: Two phase commit in ECPG
Previous Message David G. Johnston 2017-03-17 18:25:26 Re: BUG #14512: Backslashes in LIKE