From 79241e1e4a7eef01661766a62c12f0f1324a9657 Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Wed, 21 Oct 2026 20:51:20 +0900 Subject: [PATCH v1 1/2] Add a test for a COLLATE clause in the URI of XMLNAMESPACES A view whose XMLNAMESPACES URI has a COLLATE clause is pretty-printed with the clause bare: XMLTABLE(XMLNAMESPACES ('http://x.y'::text COLLATE "C" AS p), ... The URI is a b_expr in the grammar, which does not accept COLLATE, so the definition cannot be read back: syntax error at or near "COLLATE". The expected output shows the behavior before the fix. The next commit fixes it and updates the output. --- src/test/regress/expected/xml.out | 18 ++++++++++++++++++ src/test/regress/sql/xml.sql | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out index 6998745ee03..cdfc2a03637 100644 --- a/src/test/regress/expected/xml.out +++ b/src/test/regress/expected/xml.out @@ -1933,3 +1933,21 @@ SELECT xmltext('x'|| '

73

'::xml || .42 || true || 'j'::char); x<P>73</P>0.42truej (1 row) +-- The namespace URI of XMLNAMESPACES is a b_expr, so a COLLATE clause in it +-- needs parentheses, which pretty-printed output does not add by itself +CREATE VIEW xmltableview_collate AS +SELECT * FROM XMLTABLE(XMLNAMESPACES(('http://x.y' COLLATE "C") AS p), + '/p:a' PASSING (NULL::xml) COLUMNS v text PATH 'p:b'); +SELECT pg_get_viewdef('xmltableview_collate'::regclass, true); + pg_get_viewdef +---------------------------------------------------------------------------------------------------------------------------------------------- + SELECT v + + FROM XMLTABLE(XMLNAMESPACES ('http://x.y'::text COLLATE "C" AS p), ('/p:a'::text) PASSING (NULL::xml) COLUMNS v text PATH ('p:b'::text)); +(1 row) + +SELECT pg_get_viewdef('xmltableview_collate'::regclass, true) AS def \gset +CREATE OR REPLACE VIEW xmltableview_collate AS :def +ERROR: syntax error at or near "COLLATE" +LINE 2: ... FROM XMLTABLE(XMLNAMESPACES ('http://x.y'::text COLLATE "C... + ^ +DROP VIEW xmltableview_collate; diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql index 0581d21b03f..f27960ca9bb 100644 --- a/src/test/regress/sql/xml.sql +++ b/src/test/regress/sql/xml.sql @@ -724,3 +724,13 @@ SELECT xmltext(' '); SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}'); SELECT xmltext('foo & <"bar">'); SELECT xmltext('x'|| '

73

'::xml || .42 || true || 'j'::char); + +-- The namespace URI of XMLNAMESPACES is a b_expr, so a COLLATE clause in it +-- needs parentheses, which pretty-printed output does not add by itself +CREATE VIEW xmltableview_collate AS +SELECT * FROM XMLTABLE(XMLNAMESPACES(('http://x.y' COLLATE "C") AS p), + '/p:a' PASSING (NULL::xml) COLUMNS v text PATH 'p:b'); +SELECT pg_get_viewdef('xmltableview_collate'::regclass, true); +SELECT pg_get_viewdef('xmltableview_collate'::regclass, true) AS def \gset +CREATE OR REPLACE VIEW xmltableview_collate AS :def +DROP VIEW xmltableview_collate; -- 2.54.0 (Apple Git-157)