| From: | 신성준 <shinsj4653(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers mailing list <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Cc: | Henson Choi <assam258(at)gmail(dot)com> |
| Subject: | Fix deparsing of SUBSTRING SIMILAR with an operator as first argument |
| Date: | 2026-11-26 13:18:18 |
| Message-ID: | CACdN0M6mUp_Yzm7YAh=MRWFyMOxMatapqqyPB0oyZ7T+Jt3A=A@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi hackers,
pg_get_viewdef() prints the first argument of SUBSTRING(... SIMILAR
... ESCAPE ...) without parentheses. Since SIMILAR binds more tightly
than comparison operators, an argument like "s < 1" comes out in a
form that doesn't parse:
CREATE FUNCTION f(text, int) RETURNS text
LANGUAGE sql IMMUTABLE AS 'SELECT $1 || $2';
CREATE OPERATOR < (LEFTARG = text, RIGHTARG = int, FUNCTION = f);
CREATE VIEW v AS
SELECT substring((s < 1) SIMILAR '%#"1#"' ESCAPE '#') AS a
FROM (VALUES ('x'::text)) t(s);
pg_get_viewdef('v', true) gives
SELECT SUBSTRING(s < 1 SIMILAR '%#"1#"'::text ESCAPE '#'::text) AS a
FROM ( VALUES ('x'::text)) t(s);
which fails with a syntax error when run again, so a dump containing
such a view can't be restored.
The attached patch prints that argument with get_rule_expr_paren(), as
the IS NORMALIZED case does. The other two arguments don't need it.
Best regards,
Seongjun Shin
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fix-deparsing-of-SUBSTRING-SIMILAR-with-an-operat.patch | application/octet-stream | 3.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Álvaro Herrera | 2026-11-26 13:19:15 | Re: Fix LogStandbySnapshot() race during logical decoding activation |
| Previous Message | 신성준 | 2026-11-26 13:16:53 | Preserve tablespace of exclusion constraint indexes in ALTER TYPE |