Hi The in-core XPATH() function currently only handles XPath expressions which return a node set correctly. For XPath expressions which return boolean, numeric or string values, XPATH() returns an empty array. (This is the case for XPath expressions whose top-level syntactic construct isn't a path expression but rather one of the built-in functions like name() or count()).
The XPath expression 'name(/*)', for example, is supposed to return 'root' when applied to the XML fragment '<root><nested/><nested/></root>'. Postgres, however, currently returns an empty array. A patch which fixes that is attached. It makes XPATH() return a single-element array containing a textual representation of the string, numeric value or boolean for XPath expressions which don't return a node set. For numeric and boolean results, the textual representation is obtained by calling float8out() respectively boolout(). These function's results are assumed to always be well-form XML. For string results, xml_in() is used to verify that the string returned by the XPath expression is a well-formed XML fragment. This is required because XPATH() could otherwise be used to insert invalid XML fragments into columns of type XML. The patch add a few tests of non-nodeset returning XPath expressions to the XML regression tests. I'm not 100% clear on whether I should add this to the next commit fest or not - after all, it's more a bug-fix rather than a new feature. But to prevent this from getting lost, I'll add it unless someone tells me not to. best regards, Florian Pflug
pg_xpath_returnvalue.v1.patch
Description: Binary data
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers