You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix minor deficiencies in XMLTABLE, xpath(), xmlexists()
Correctly process nodes of more types than previously. In some cases,
nodes were being ignored (nothing was output); in other cases, trying to
return them resulted in errors about unrecognized nodes. In yet other
cases, necessary escaping (of XML special characters) was not being
done. Fix all those (as far as the authors could find) and add
regression tests cases verifying the new behavior.
I (Álvaro) was of two minds about backpatching these changes. They do
seem bugfixes that would benefit most users of the affected functions;
but on the other hand it would change established behavior in minor
releases, so it seems prudent not to.
Authors: Pavel Stehule, Markus Winand, Chapman Flack
Discussion:
https://postgr.es/m/CAFj8pRA6J25CtAZ2TuRvxK3gat7-bBUYh0rfE2yM7Hj9GD14Dg@mail.gmail.comhttps://postgr.es/m/8BDB0627-2105-4564-AA76-7849F028B96E@winand.at
The elephant in the room as pointed out by Chapman Flack, not fixed in
this commit, is that we still have XMLTABLE operating on XPath 1.0
instead of the standard-mandated XQuery (or even its subset XPath 2.0).
Fixing that is a major undertaking, however.
Copy file name to clipboardExpand all lines: src/test/regress/expected/xml.out
+24-3Lines changed: 24 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1210,9 +1210,9 @@ SELECT xmltable.* FROM xmldata, LATERAL xmltable('/ROWS/ROW[COUNTRY_NAME="Japan"
1210
1210
(2 rows)
1211
1211
1212
1212
SELECT * FROM xmltable('/root' passing '<root><element>a1a<!-- aaaa -->a2a<?aaaaa?> <!--z--> bbbb<x>xxx</x>cccc</element></root>' COLUMNS element text);
1213
-
element
1214
-
-------------------
1215
-
a1aa2a bbbbcccc
1213
+
element
1214
+
----------------------
1215
+
a1aa2a bbbbxxxcccc
1216
1216
(1 row)
1217
1217
1218
1218
SELECT * FROM xmltable('/root' passing '<root><element>a1a<!-- aaaa -->a2a<?aaaaa?> <!--z--> bbbb<x>xxx</x>cccc</element></root>' COLUMNS element text PATH 'element/text()'); -- should fail
SELECT * FROM XMLTABLE('*' PASSING '<a>a</a>' COLUMNS a xml PATH '.', b text PATH '.', c text PATH '"hi"', d boolean PATH '. = "a"', e integer PATH 'string-length(.)');
1498
+
a | b | c | d | e
1499
+
----------+---+----+---+---
1500
+
<a>a</a> | a | hi | t | 1
1501
+
(1 row)
1502
+
1503
+
\x
1504
+
SELECT * FROM XMLTABLE('*' PASSING '<e>pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n2>&deep</n2>post</e>' COLUMNS x xml PATH 'node()', y xml PATH '/');
1505
+
-[ RECORD 1 ]-----------------------------------------------------------
1506
+
x | pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n2>&deep</n2>post
1507
+
y | <e>pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n2>&deep</n2>post</e>+
1508
+
|
1509
+
1510
+
\x
1511
+
SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH '"<foo/>"', b xml PATH '"<foo/>"');
SELECT * FROM XMLTABLE('*' PASSING '<a>a</a>' COLUMNS a xml PATH '.', b text PATH '.', c text PATH '"hi"', d boolean PATH '. = "a"', e integer PATH 'string-length(.)');
1348
+
ERROR: unsupported XML feature
1349
+
LINE 1: SELECT * FROM XMLTABLE('*' PASSING '<a>a</a>' COLUMNS a xml ...
1350
+
^
1351
+
DETAIL: This functionality requires the server to be built with libxml support.
1352
+
HINT: You need to rebuild PostgreSQL using --with-libxml.
1353
+
\x
1354
+
SELECT * FROM XMLTABLE('*' PASSING '<e>pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n2>&deep</n2>post</e>' COLUMNS x xml PATH 'node()', y xml PATH '/');
1355
+
ERROR: unsupported XML feature
1356
+
LINE 1: SELECT * FROM XMLTABLE('*' PASSING '<e>pre<!--c1--><?pi arg?...
1357
+
^
1358
+
DETAIL: This functionality requires the server to be built with libxml support.
1359
+
HINT: You need to rebuild PostgreSQL using --with-libxml.
1360
+
\x
1361
+
SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH '"<foo/>"', b xml PATH '"<foo/>"');
1362
+
ERROR: unsupported XML feature
1363
+
DETAIL: This functionality requires the server to be built with libxml support.
1364
+
HINT: You need to rebuild PostgreSQL using --with-libxml.
Copy file name to clipboardExpand all lines: src/test/regress/expected/xml_2.out
+24-3Lines changed: 24 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1190,9 +1190,9 @@ SELECT xmltable.* FROM xmldata, LATERAL xmltable('/ROWS/ROW[COUNTRY_NAME="Japan"
1190
1190
(2 rows)
1191
1191
1192
1192
SELECT * FROM xmltable('/root' passing '<root><element>a1a<!-- aaaa -->a2a<?aaaaa?> <!--z--> bbbb<x>xxx</x>cccc</element></root>' COLUMNS element text);
1193
-
element
1194
-
-------------------
1195
-
a1aa2a bbbbcccc
1193
+
element
1194
+
----------------------
1195
+
a1aa2a bbbbxxxcccc
1196
1196
(1 row)
1197
1197
1198
1198
SELECT * FROM xmltable('/root' passing '<root><element>a1a<!-- aaaa -->a2a<?aaaaa?> <!--z--> bbbb<x>xxx</x>cccc</element></root>' COLUMNS element text PATH 'element/text()'); -- should fail
SELECT * FROM XMLTABLE('*' PASSING '<a>a</a>' COLUMNS a xml PATH '.', b text PATH '.', c text PATH '"hi"', d boolean PATH '. = "a"', e integer PATH 'string-length(.)');
1478
+
a | b | c | d | e
1479
+
----------+---+----+---+---
1480
+
<a>a</a> | a | hi | t | 1
1481
+
(1 row)
1482
+
1483
+
\x
1484
+
SELECT * FROM XMLTABLE('*' PASSING '<e>pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n2>&deep</n2>post</e>' COLUMNS x xml PATH 'node()', y xml PATH '/');
1485
+
-[ RECORD 1 ]-----------------------------------------------------------
1486
+
x | pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n2>&deep</n2>post
1487
+
y | <e>pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n2>&deep</n2>post</e>+
1488
+
|
1489
+
1490
+
\x
1491
+
SELECT * FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH '"<foo/>"', b xml PATH '"<foo/>"');
Copy file name to clipboardExpand all lines: src/test/regress/sql/xml.sql
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -595,3 +595,11 @@ INSERT INTO xmltest2 VALUES('<d><r><dc>2</dc></r></d>', 'D');
595
595
SELECT xmltable.*FROM xmltest2, LATERAL xmltable('/d/r' PASSING x COLUMNS a intPATH''||lower(_path) ||'c');
596
596
SELECT xmltable.*FROM xmltest2, LATERAL xmltable(('/d/r/'||lower(_path) ||'c') PASSING x COLUMNS a intPATH'.');
597
597
SELECT xmltable.*FROM xmltest2, LATERAL xmltable(('/d/r/'||lower(_path) ||'c') PASSING x COLUMNS a intPATH'x' DEFAULT ascii(_path) -54);
598
+
599
+
-- XPath result can be boolean or number too
600
+
SELECT*FROM XMLTABLE('*' PASSING '<a>a</a>' COLUMNS a xml PATH'.', b textPATH'.', c textPATH'"hi"', d booleanPATH'. = "a"', e integerPATH'string-length(.)');
601
+
\x
602
+
SELECT*FROM XMLTABLE('*' PASSING '<e>pre<!--c1--><?pi arg?><![CDATA[&ent1]]><n2>&deep</n2>post</e>' COLUMNS x xml PATH'node()', y xml PATH'/');
603
+
\x
604
+
605
+
SELECT*FROM XMLTABLE('.' PASSING XMLELEMENT(NAME a) columns a varchar(20) PATH'"<foo/>"', b xml PATH'"<foo/>"');
0 commit comments