Re: SIMILAR TO expressions translate wildcards where they shouldn't
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2025-05-27T05:57:45Z
Lists: pgsql-bugs
Attachments
- v3-0001-Fix-SIMILAR-TO-regex-translation-for-character-cl.patch (text/x-diff) patch v3-0001
On Fri, May 23, 2025 at 11:42:10AM +0200, Laurenz Albe wrote:
> I also improved the code by adding more comments.
> I renamed "incharclass" to "charclass_depth", which is more descriptive.
>
> Also, I had to work some more on handling carets:
> While the closing bracket is a regular character in []] and [^]], it
> is not in expressions like [^^].
The transformation with the patch:
'^(?:\.[.[:alnum:]_].[]%].*[^]$]\$[^^]\^[(](?:p))$'
And on HEAD:
'^(?:\.[.[:alnum:].].[].*].*[^]\$]\$[^^]\^[(](?:p))$'
If I am not missing something, '%', '_', '$', single and double carets
at the beginning are covered. '.' and '(' are not.
Anyway, that's really hard to parse so I would suggest to split each
check into queries of their own to show individual conversions in
these EXPLAIN outputs (we don't care if tese regexps are correct, just
want to check the output to the POSIX style). I am OK with the point
based on charclass_start to count the number of carets at the
beginning of a character class.
With some tweaks and the tests reworked, I am finishing with the
reviewed version attached. What do you think?
--
Michael
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Adjust regex for test with opening parenthesis in character classes
- 31ee5ec698ed 13.22 landed
- 0c09922c04ea 14.19 landed
- 4dc642e75f1c 15.14 landed
- 52d08620e48c 16.10 landed
- a3c6d92f3cb3 17.6 landed
- 4fbb46f61271 18.0 landed
-
Fix conversion of SIMILAR TO regexes for character classes
- 9481d1614c2a 13.22 landed
- 1fe15d25e65c 14.19 landed
- b3e99115e44c 15.14 landed
- e9e535d61120 16.10 landed
- e3ffc3e91d04 17.6 landed
- d46911e584d4 18.0 landed