Re: xpath() subquery for empty array

From: Scott Bailey <artacus(at)comcast(dot)net>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: xpath() subquery for empty array
Date: 2009-07-12 15:56:35
Message-ID: 4A5A07B3.10504@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Roy Walter wrote:
> In postgres 8.4 When running xpath() queries it seems that empty results
> are always returned. So if I query a table containing 1000 XML documents
> a 1000 rows will always be fetched even if the xpath() element of the
> query only matches 10 documents.
>
> The documentation states:
>
> The function |xpath| evaluates the XPath expression /xpath/ against
> the XML value /xml/. It returns an array of XML values corresponding
> to the node set produced by the XPath expression.
>
> Yet it seems that empty node sets (arrays) are also returned. So, my
> thought was to run a subquery to eliminate empty arrays, e.g.:
>
> SELECT x
> FROM (SELECT xpath('//entry[contains(p, ''searchtext'')]/@*', docxml)
> AS x FROM docs) AS y WHERE x <> [test for empty array?????????]
>
> How do I test for an empty array in postgres?
>
> Thanks in advance,
> Roy

WHERE x != array[]::xml[]

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2009-07-12 16:03:17 Re: Checkpoint Tuning Question
Previous Message David Fetter 2009-07-12 15:53:50 Re: [BUGS] BUG #4916: wish: more statistical functions (median, percentiles etc)