Re: ANY for Array value check

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: ANY for Array value check
Date: 2011-06-11 09:59:42
Message-ID: isveae$knm$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 2011-06-10, Emi Lu <emilu(at)encs(dot)concordia(dot)ca> wrote:
> Good morning,
>
> String array compare command, I forgot how to do it.
>
> E.g.,
> create table z_drop(id varchar[]);
> insert into z_drop values('{"a1", "a2", "b1", "b2", "b3"}');
>
> I'd like to do:
>
> select * from z_drop where id = any('a1', 'b1');

use the array overlap operator:

select * from z_drop where id && ARRAY['a1'::varchar, 'b1'];

If you define the column as text[] instead of varchar you don't need
the ::varchar cast above. there's no postgres reason to prefer
(unbounded) varchar to text.

--
⚂⚃ 100% natural

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Leif Biberg Kristensen 2011-06-11 15:01:54 Subselects not allowed?
Previous Message Samuel Gendler 2011-06-11 05:11:37 Re: Returning a set of dates