Re: BUG #18765: Inconsistent behaviour and errors with LIKE

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: anmol(dot)mohanty(at)salesforce(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18765: Inconsistent behaviour and errors with LIKE
Date: 2025-01-03 17:21:24
Message-ID: CAKFQuwaoWrRuM544zDqnTg2wnB8fkQgOe0qAHrvHmDQgAyLGcw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Jan 3, 2025 at 10:04 AM PG Bug reporting form <
noreply(at)postgresql(dot)org> wrote:

> The following bug has been logged on the website:
>
> Bug reference: 18765
> Logged by: Anmol Mohanty
> Email address: anmol(dot)mohanty(at)salesforce(dot)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.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-01-03 17:58:23 Re: BUG #18764: server closed the connection unexpectedly
Previous Message PG Bug reporting form 2025-01-03 17:04:26 BUG #18766: not exists sometimes gives too few records