aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/utils/adt/xml.c7
-rw-r--r--src/test/regress/expected/xml.out4
-rw-r--r--src/test/regress/expected/xml_1.out8
-rw-r--r--src/test/regress/expected/xml_2.out4
-rw-r--r--src/test/regress/sql/xml.sql4
5 files changed, 26 insertions, 1 deletions
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 48d98e96cf5..edac2754aba 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -4612,6 +4612,12 @@ XmlTableGetValue(TableFuncScanState *state, int colnum,
xmlChar *str;
xmlNodePtr node;
+ node = xpathobj->nodesetval->nodeTab[0];
+ if (node->type == XML_NAMESPACE_DECL)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("XMLTABLE cannot cast a namespace node to a non-XML result type")));
+
/*
* Most nodes (elements and even attributes) store their data
* in children nodes. If they don't have children nodes, it
@@ -4619,7 +4625,6 @@ XmlTableGetValue(TableFuncScanState *state, int colnum,
* CDATA sections are an exception: they don't have children
* but have content in the Text/CDATA node itself.
*/
- node = xpathobj->nodesetval->nodeTab[0];
if (node->type != XML_CDATA_SECTION_NODE &&
node->type != XML_TEXT_NODE)
node = node->xmlChildrenNode;
diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out
index 2ed0d44b1e0..39058a007f1 100644
--- a/src/test/regress/expected/xml.out
+++ b/src/test/regress/expected/xml.out
@@ -1173,6 +1173,10 @@ SELECT * FROM XMLTABLE(XMLNAMESPACES(DEFAULT 'http://x.y'),
PASSING '<rows xmlns="http://x.y"><row><a>10</a></row></rows>'
COLUMNS a int PATH 'a');
ERROR: DEFAULT namespace is not supported
+SELECT * FROM XMLTABLE('.'
+ PASSING '<foo/>'
+ COLUMNS a text PATH 'foo/namespace::node()');
+ERROR: XMLTABLE cannot cast a namespace node to a non-XML result type
-- used in prepare statements
PREPARE pp AS
SELECT xmltable.*
diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out
index 9dd9b3f7ca5..4d8eaaf4ec7 100644
--- a/src/test/regress/expected/xml_1.out
+++ b/src/test/regress/expected/xml_1.out
@@ -1048,6 +1048,14 @@ LINE 3: PASSING '<rows xmlns="http://x.y"><row...
^
DETAIL: This functionality requires the server to be built with libxml support.
HINT: You need to rebuild PostgreSQL using --with-libxml.
+SELECT * FROM XMLTABLE('.'
+ PASSING '<foo/>'
+ COLUMNS a text PATH 'foo/namespace::node()');
+ERROR: unsupported XML feature
+LINE 2: PASSING '<foo/>'
+ ^
+DETAIL: This functionality requires the server to be built with libxml support.
+HINT: You need to rebuild PostgreSQL using --with-libxml.
-- used in prepare statements
PREPARE pp AS
SELECT xmltable.*
diff --git a/src/test/regress/expected/xml_2.out b/src/test/regress/expected/xml_2.out
index 6fe363142bf..74a2ddd3b77 100644
--- a/src/test/regress/expected/xml_2.out
+++ b/src/test/regress/expected/xml_2.out
@@ -1153,6 +1153,10 @@ SELECT * FROM XMLTABLE(XMLNAMESPACES(DEFAULT 'http://x.y'),
PASSING '<rows xmlns="http://x.y"><row><a>10</a></row></rows>'
COLUMNS a int PATH 'a');
ERROR: DEFAULT namespace is not supported
+SELECT * FROM XMLTABLE('.'
+ PASSING '<foo/>'
+ COLUMNS a text PATH 'foo/namespace::node()');
+ERROR: XMLTABLE cannot cast a namespace node to a non-XML result type
-- used in prepare statements
PREPARE pp AS
SELECT xmltable.*
diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql
index 4e844234c53..9af7cd7aeb7 100644
--- a/src/test/regress/sql/xml.sql
+++ b/src/test/regress/sql/xml.sql
@@ -402,6 +402,10 @@ SELECT * FROM XMLTABLE(XMLNAMESPACES(DEFAULT 'http://x.y'),
PASSING '<rows xmlns="http://x.y"><row><a>10</a></row></rows>'
COLUMNS a int PATH 'a');
+SELECT * FROM XMLTABLE('.'
+ PASSING '<foo/>'
+ COLUMNS a text PATH 'foo/namespace::node()');
+
-- used in prepare statements
PREPARE pp AS
SELECT xmltable.*