Re: How to check if an array is empty

From: "Hitoshi Harada" <umi(dot)tanuki(at)gmail(dot)com>
To: "Tobias Anstett" <tobias(dot)anstett(at)iaas(dot)uni-stuttgart(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to check if an array is empty
Date: 2008-09-15 06:50:21
Message-ID: e08cc0400809142350l10ca00b1j4bf0063b3643c3bd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2008/9/11 Tobias Anstett <tobias(dot)anstett(at)iaas(dot)uni-stuttgart(dot)de>:
> Hi,
>
>
>
> in my special case I'd like to check if a XML[] is empty, because postgres
> doesn't implement any equality operators, this is not a 'simple' task.
>
>
>
> My current solution is:
>
>
>
> SELECT * FROM sometable WHERE XMLSERIALIZE(CONTENT ((XPATH('/a:bar,
> somexmlcolumn, ARRAY[ARRAY['a', 'http://foo]]))[1]) AS text)<>''
>
>
>
> But there must be a better way – maybe I missed something important - I also
> tried queries like the following:
>
>
>
> SELECT * FROM sometable WHERE (XPATH('/a:bar', somexmlcolumn,
> ARRAY[ARRAY['a', 'http://foo']]))<>('{}'::XML[])
>
>
>
> Any ideas and feedback are welcome.
>
>
>
> Cheers, Tobias

What about array_upper():

select array_upper('{}'::XML[], 1)

NULL will be returned if the array is empty in 1-dim.

--
Hitoshi Harada

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2008-09-15 06:52:11 Re: Statement level trigger clarification
Previous Message Greg Smith 2008-09-15 06:42:32 Re: Pg 8.3 tuning recommendations for embedded low-memory device (for OLPC :-) )