Skip site navigation (1) Skip section navigation (2)

[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: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers

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: pg_xpath_returnvalue.v1.patch
Description: application/octet-stream (8.3 KB)


pgsql-hackers by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group