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

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 (view raw or flat)
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

pgsql-general by date

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

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