Re: How to select rows for which column has empty array ?

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to select rows for which column has empty array ?
Date: 2014-06-06 15:12:48
Message-ID: 1402067568574-5806343.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Arup Rakshit wrote
> I have a below table :
>
> yelloday_development=# select id,workplace_ids,team_ids  from
> reporting_groups ;                                                        
>                                                                          
>                                                   
>  id | workplace_ids | team_ids 
> ----+---------------+----------
>   2 | {}            | {}
>   3 | {}            | {}
>   1 | {}            | {}
>   4 | {1}           | {1}
>   5 | {2}           | {2,3,4}
> (5 rows)
>
> yelloday_development=# select id from reporting_groups where 2 = ANY
> (team_ids)
> yelloday_development-# ;
>  id 
> ----
>   5
> (1 row)
>
> How would I select rows which has empty array for the field "team_ids" ?

The generic way would be to checks its length:

WHERE array_length(team_ids, 1) = 0

you could also check for equality with the empty array:

WHERE teams_ids = array[]::integer[]

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-select-rows-for-which-column-has-empty-array-tp5806338p5806343.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2014-06-06 16:05:52 Problem with locales on Linux with 9.3.4
Previous Message Stefan Froehlich 2014-06-06 14:57:10 Re: interpret bytea output as text / double encode()