XMLTable treats a column of a domain over xml as a non-xml column
Hi
XMLTable handles a column whose type is a domain over xml as if it were
a plain non-xml column:
== master ==
postgres=# create domain xmldom as xml;
CREATE DOMAIN
postgres=# select * from
xmltable('/r' passing '<r><a>x</a></r>'
columns c1 xml path 'a',
c2 xmldom path 'a');
c1 | c2
----------+----
<a>x</a> | x
(1 row)
Since xmldom in this examplw is a domain over xml, both columns should
return the same value,but c2 only gets the node's string value.
For boolean results xmltable already looks through domains:
postgres=# create domain intdom as int;
CREATE DOMAIN
postgres=# select * from
xmltable('/r' passing '<r/>'
columns c1 int path 'true()',
c2 intdom path 'true()',
c3 text path 'true()');
c1 | c2 | c3
----+----+------
1 | 1 | true
(1 row)
It picks 1/0 or true/false by type category,which a domain inherits, so
the intdom column behaves like the int column. The xml check should do
the same.
The cause is that XmlTableGetValue() tests typid == XMLOID, which does
not consider domains. The attached patch resolves domains to their base
type with getBaseType() before that test, and adds a regression test.
== patched ==
postgres=# select * from
xmltable('/r' passing '<r><a>x</a></r>'
columns c1 xml path 'a',
c2 xmldom path 'a');
c1 | c2
----------+----------
<a>x</a> | <a>x</a>
(1 row)
Best, Jim
Hi,
Thank you for the patch, Jim.
I tested v1-0001 on current master (8303f2e), built with
--with-libxml and --enable-cassert. The patch applied cleanly.
Without the patch, I could reproduce the problem. With your example,
column c2 (domain over xml) returns "x", while the xml column c1
returns "<a>x</a>". With the patch, both columns return "<a>x</a>".
The SQL from your new regression test fails on master with "more than
one value returned by column XPath expression" and works with the patch.
I also tried a few variations. With the patch:
* A domain over another domain over xml behaves like xml.
* A domain over xml with CHECK (value IS DOCUMENT) returns the
document for path '.', and raises the check constraint error when
the path returns two elements.
* An empty element <a/> and a comment() result in a domain column
look the same as in an xml column.
* Columns of type text, varchar, and domains over text and int gave
the same result as without the patch.
* A "default" clause and a no-match path gave the same result as
without the patch.
* FOR ORDINALITY together with a domain column works.
I read the change in XmlTableGetValue(). It looks small and clear to
me. The domain's own input function is still used, so the domain
constraints still run.
What I did not test:
* make check or make check-world, and the TAP tests.
* The xml regression test itself against an unpatched tree.
* Other platforms, or builds without libxml.
* Domain over xml with a typmod, or domain over an array of xml.
* Whether other places in xml.c need the same getBaseType() change.
Thank you again for working on this.
Best regards,
Joao Rito
Hi Jim,
A small follow-up to my earlier message, because I listed "make check" as
not tested.
I ran it afterwards on master (8303f2e), built with --with-libxml and
--enable-cassert. "make check" passes on unpatched master (243 tests) and
with your patch applied (243 tests). The xml and xmlmap tests pass in both
runs, and there is no regression.diffs. The build with libxml uses
expected/xml.out. I did not run the build without libxml, which uses
xml_1.out, and I see the patch does not change that file.
Thanks again for the patch.
Best regards,
Joao Rito