Re: BUG #18765: Inconsistent behaviour and errors with LIKE - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: BUG #18765: Inconsistent behaviour and errors with LIKE
Date
Msg-id CAKFQuwaoWrRuM544zDqnTg2wnB8fkQgOe0qAHrvHmDQgAyLGcw@mail.gmail.com
Whole thread Raw
In response to BUG #18765: Inconsistent behaviour and errors with LIKE  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
On Fri, Jan 3, 2025 at 10:04 AM PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      18765
Logged by:          Anmol Mohanty
Email address:      anmol.mohanty@salesforce.com
PostgreSQL version: 17.0
Operating system:   NA(used fiddle tool at sqlfiddle.com)
Description:       

select 'a\' like 'a\'; -- error - LIKE pattern must not end with escape
character
select 'a' like 'a\'; -- f - query runs
This doesn't make sense. The LIKE pattern is incorrect in both.

I've also checked around constant folding and runtime non-literal values by
inserting into cte's and temp tables. Same outcome.

```
WITH a AS (SELECT 'xyz' AS value)
SELECT value LIKE 'xyz\' AS result
FROM a;
```
f


Working as designed.

Execution optimization combined with non-compilation.

You may not get a failure if the condition is proven to evaluate to false before encountering the malformed part of the expression.  There is no compilation step that evaluates the supplied text for correctness independent of its usage.  The input string running out of characters while the test string still has some is known to result in a false outcome.

David J.

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #18766: not exists sometimes gives too few records
Next
From: Tom Lane
Date:
Subject: Re: BUG #18764: server closed the connection unexpectedly