[PATCH] Bug in XPATH() if expression returns a scalar value

From: Florian Pflug <fgp(at)phlo(dot)org>
To: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Bug in XPATH() if expression returns a scalar value
Date: 2011-05-30 13:17:02
Message-ID: 33B182D9-D2C3-4BDF-A8C9-B896BC9B8629@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
pg_xpath_returnvalue.v1.patch application/octet-stream 8.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kim Bisgaard 2011-05-30 13:56:08 Re: Getting a bug tracker for the Postgres project
Previous Message Heikki Linnakangas 2011-05-30 12:55:59 Re: Small patch for GiST: move childoffnum to child