BUG #15084: Invalid LIKE pattern not always reported

Started by PG Bug reporting formabout 8 years ago3 messagesbugs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 15084
Logged by: Tudor Bosman
Email address: tudorb@gmail.com
PostgreSQL version: 9.5.11
Operating system: Ubuntu 16.04
Description:

PostgreSQL will not always detect an invalid LIKE pattern (one that ends
with a backslash).

Example:

tudor=# select 'foo' like 'foo\';
?column?
----------
f
(1 row)

tudor=# select 'foobar' like 'foo\';
ERROR: LIKE pattern must not end with escape character

This probably happens because the pattern is only parsed lazily (as needed);
if PostgreSQL detects that a match is impossible, it doesn't even look at
the rest of the pattern.

Still, it would be nice for error reporting to be consistent.

Thanks,
-Tudor.

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: PG Bug reporting form (#1)
Re: BUG #15084: Invalid LIKE pattern not always reported

On Fri, Feb 23, 2018 at 1:29 PM, PG Bug reporting form <
noreply@postgresql.org> wrote:

The following bug has been logged on the website:

Bug reference: 15084
Logged by: Tudor Bosman
Email address: tudorb@gmail.com
PostgreSQL version: 9.5.11
Operating system: Ubuntu 16.04
Description:

PostgreSQL will not always detect an invalid LIKE pattern (one that ends
with a backslash).

Example:

tudor=# select 'foo' like 'foo\';
?column?
----------
f
(1 row)

tudor=# select 'foobar' like 'foo\';
ERROR: LIKE pattern must not end with escape character

This probably happens because the pattern is only parsed lazily (as
needed);
if PostgreSQL detects that a match is impossible, it doesn't even look at
the rest of the pattern.

Still, it would be nice for error reporting to be consistent.

​Last March (Bug# 14512) Tom Lane thought a performant solution was
possible though it was never committed.

/messages/by-id/28169.1489781085@sss.pgh.pa.us

I'm still +1 if it can be done without hurting performance on patterns that
do match - a compile-time failure here is desirable.

Full thread here:

/messages/by-id/20170124172505.1431.56735@wrigleys.postgresql.org

David J.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: PG Bug reporting form (#1)
Re: BUG #15084: Invalid LIKE pattern not always reported

=?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:

PostgreSQL will not always detect an invalid LIKE pattern (one that ends
with a backslash).
This probably happens because the pattern is only parsed lazily (as needed);
if PostgreSQL detects that a match is impossible, it doesn't even look at
the rest of the pattern.

Yeah, exactly.

Still, it would be nice for error reporting to be consistent.

This has been discussed before, but nobody could see how to do it without
taking a performance hit (ie, doing a full scan of the pattern before
doing any actual work). It didn't seem worth that.

It occurs to me that we could make the behavior more consistent by
redefining a trailing backslash as something we silently ignore, instead
of raising an error. Not sure if that's an improvement, though.

regards, tom lane