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 toreturn them resulted in errors about unrecognized nodes. In yet othercases, necessary escaping (of XML special characters) was not beingdone. Fix all those (as far as the authors could find) and addregression tests cases verifying the new behavior.I (Álvaro) was of two minds about backpatching these changes. They doseem bugfixes that would benefit most users of the affected functions;but on the other hand it would change established behavior in minorreleases, so it seems prudent not to.Authors: Pavel Stehule, Markus Winand, Chapman FlackDiscussion:https://postgr.es/m/CAFj8pRA6J25CtAZ2TuRvxK3gat7-bBUYh0rfE2yM7Hj9GD14Dg@mail.gmail.comhttps://postgr.es/m/8BDB0627-2105-4564-AA76-7849F028B96E@winand.atThe elephant in the room as pointed out by Chapman Flack, not fixed inthis commit, is that we still have XMLTABLE operating on XPath 1.0instead 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
-
a1aa2abbbbcccc
1213
+
element
1214
+
----------------------
1215
+
a1aa2abbbbxxxcccc
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
-
a1aa2abbbbcccc
1193
+
element
1194
+
----------------------
1195
+
a1aa2abbbbxxxcccc
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/>"');