Skip to content

Commit 2e0f93d

Browse files
committed
Add missing deparsing of [NO] IDENT to XMLSERIALIZE()
NO INDENT is the default, and is added if no explicit indentation flag was provided with XMLSERIALIZE(). Oversight in 483bdb2. Author: Jim Jones <jim.jones@uni-muenster.de> Discussion: https://postgr.es/m/bebd457e-5b43-46b3-8fc6-f6a6509483ba@uni-muenster.de Backpatch-through: 16
1 parent 57dca6f commit 2e0f93d

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9898,9 +9898,16 @@ get_rule_expr(Node *node, deparse_context *context,
98989898
}
98999899
}
99009900
if (xexpr->op == IS_XMLSERIALIZE)
9901+
{
99019902
appendStringInfo(buf, " AS %s",
99029903
format_type_with_typemod(xexpr->type,
99039904
xexpr->typmod));
9905+
if (xexpr->indent)
9906+
appendStringInfoString(buf, " INDENT");
9907+
else
9908+
appendStringInfoString(buf, " NO INDENT");
9909+
}
9910+
99049911
if (xexpr->op == IS_DOCUMENT)
99059912
appendStringInfoString(buf, " IS DOCUMENT");
99069913
else

src/test/regress/expected/xml.out

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -822,21 +822,25 @@ CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar');
822822
CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
823823
CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
824824
CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
825+
CREATE VIEW xmlview10 AS SELECT xmlserialize(document '<foo><bar>42</bar></foo>' AS text indent);
826+
CREATE VIEW xmlview11 AS SELECT xmlserialize(document '<foo><bar>42</bar></foo>' AS character varying no indent);
825827
SELECT table_name, view_definition FROM information_schema.views
826828
WHERE table_name LIKE 'xmlview%' ORDER BY 1;
827-
table_name | view_definition
828-
------------+------------------------------------------------------------------------------------------------------------
829+
table_name | view_definition
830+
------------+---------------------------------------------------------------------------------------------------------------------------------------
829831
xmlview1 | SELECT xmlcomment('test'::text) AS xmlcomment;
832+
xmlview10 | SELECT XMLSERIALIZE(DOCUMENT '<foo><bar>42</bar></foo>'::xml AS text INDENT) AS "xmlserialize";
833+
xmlview11 | SELECT (XMLSERIALIZE(DOCUMENT '<foo><bar>42</bar></foo>'::xml AS character varying NO INDENT))::character varying AS "xmlserialize";
830834
xmlview2 | SELECT XMLCONCAT('hello'::xml, 'you'::xml) AS "xmlconcat";
831835
xmlview3 | SELECT XMLELEMENT(NAME element, XMLATTRIBUTES(1 AS ":one:", 'deuce' AS two), 'content&') AS "xmlelement";
832-
xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(name AS name, age AS age, salary AS pay)) AS "xmlelement" +
836+
xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(name AS name, age AS age, salary AS pay)) AS "xmlelement" +
833837
| FROM emp;
834838
xmlview5 | SELECT XMLPARSE(CONTENT '<abc>x</abc>'::text STRIP WHITESPACE) AS "xmlparse";
835839
xmlview6 | SELECT XMLPI(NAME foo, 'bar'::text) AS "xmlpi";
836840
xmlview7 | SELECT XMLROOT('<foo/>'::xml, VERSION NO VALUE, STANDALONE YES) AS "xmlroot";
837-
xmlview8 | SELECT (XMLSERIALIZE(CONTENT 'good'::xml AS character(10)))::character(10) AS "xmlserialize";
838-
xmlview9 | SELECT XMLSERIALIZE(CONTENT 'good'::xml AS text) AS "xmlserialize";
839-
(9 rows)
841+
xmlview8 | SELECT (XMLSERIALIZE(CONTENT 'good'::xml AS character(10) NO INDENT))::character(10) AS "xmlserialize";
842+
xmlview9 | SELECT XMLSERIALIZE(CONTENT 'good'::xml AS text NO INDENT) AS "xmlserialize";
843+
(11 rows)
840844

841845
-- Text XPath expressions evaluation
842846
SELECT xpath('/value', data) FROM xmltest;

src/test/regress/expected/xml_1.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,16 @@ ERROR: unsupported XML feature
583583
LINE 1: ...EATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as ...
584584
^
585585
DETAIL: This functionality requires the server to be built with libxml support.
586+
CREATE VIEW xmlview10 AS SELECT xmlserialize(document '<foo><bar>42</bar></foo>' AS text indent);
587+
ERROR: unsupported XML feature
588+
LINE 1: ...TE VIEW xmlview10 AS SELECT xmlserialize(document '<foo><bar...
589+
^
590+
DETAIL: This functionality requires the server to be built with libxml support.
591+
CREATE VIEW xmlview11 AS SELECT xmlserialize(document '<foo><bar>42</bar></foo>' AS character varying no indent);
592+
ERROR: unsupported XML feature
593+
LINE 1: ...TE VIEW xmlview11 AS SELECT xmlserialize(document '<foo><bar...
594+
^
595+
DETAIL: This functionality requires the server to be built with libxml support.
586596
SELECT table_name, view_definition FROM information_schema.views
587597
WHERE table_name LIKE 'xmlview%' ORDER BY 1;
588598
table_name | view_definition

src/test/regress/expected/xml_2.out

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,21 +808,25 @@ CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar');
808808
CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
809809
CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
810810
CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
811+
CREATE VIEW xmlview10 AS SELECT xmlserialize(document '<foo><bar>42</bar></foo>' AS text indent);
812+
CREATE VIEW xmlview11 AS SELECT xmlserialize(document '<foo><bar>42</bar></foo>' AS character varying no indent);
811813
SELECT table_name, view_definition FROM information_schema.views
812814
WHERE table_name LIKE 'xmlview%' ORDER BY 1;
813-
table_name | view_definition
814-
------------+------------------------------------------------------------------------------------------------------------
815+
table_name | view_definition
816+
------------+---------------------------------------------------------------------------------------------------------------------------------------
815817
xmlview1 | SELECT xmlcomment('test'::text) AS xmlcomment;
818+
xmlview10 | SELECT XMLSERIALIZE(DOCUMENT '<foo><bar>42</bar></foo>'::xml AS text INDENT) AS "xmlserialize";
819+
xmlview11 | SELECT (XMLSERIALIZE(DOCUMENT '<foo><bar>42</bar></foo>'::xml AS character varying NO INDENT))::character varying AS "xmlserialize";
816820
xmlview2 | SELECT XMLCONCAT('hello'::xml, 'you'::xml) AS "xmlconcat";
817821
xmlview3 | SELECT XMLELEMENT(NAME element, XMLATTRIBUTES(1 AS ":one:", 'deuce' AS two), 'content&') AS "xmlelement";
818-
xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(name AS name, age AS age, salary AS pay)) AS "xmlelement" +
822+
xmlview4 | SELECT XMLELEMENT(NAME employee, XMLFOREST(name AS name, age AS age, salary AS pay)) AS "xmlelement" +
819823
| FROM emp;
820824
xmlview5 | SELECT XMLPARSE(CONTENT '<abc>x</abc>'::text STRIP WHITESPACE) AS "xmlparse";
821825
xmlview6 | SELECT XMLPI(NAME foo, 'bar'::text) AS "xmlpi";
822826
xmlview7 | SELECT XMLROOT('<foo/>'::xml, VERSION NO VALUE, STANDALONE YES) AS "xmlroot";
823-
xmlview8 | SELECT (XMLSERIALIZE(CONTENT 'good'::xml AS character(10)))::character(10) AS "xmlserialize";
824-
xmlview9 | SELECT XMLSERIALIZE(CONTENT 'good'::xml AS text) AS "xmlserialize";
825-
(9 rows)
827+
xmlview8 | SELECT (XMLSERIALIZE(CONTENT 'good'::xml AS character(10) NO INDENT))::character(10) AS "xmlserialize";
828+
xmlview9 | SELECT XMLSERIALIZE(CONTENT 'good'::xml AS text NO INDENT) AS "xmlserialize";
829+
(11 rows)
826830

827831
-- Text XPath expressions evaluation
828832
SELECT xpath('/value', data) FROM xmltest;

src/test/regress/sql/xml.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar');
219219
CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
220220
CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
221221
CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
222+
CREATE VIEW xmlview10 AS SELECT xmlserialize(document '<foo><bar>42</bar></foo>' AS text indent);
223+
CREATE VIEW xmlview11 AS SELECT xmlserialize(document '<foo><bar>42</bar></foo>' AS character varying no indent);
222224

223225
SELECT table_name, view_definition FROM information_schema.views
224226
WHERE table_name LIKE 'xmlview%' ORDER BY 1;

0 commit comments

Comments
 (0)