pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ANY for Array value check
2+ messages / 2 participants
[nested] [flat]

* ANY for Array value check
@ 2011-06-10 15:10  Emi Lu <emilu@encs.concordia.ca>
  0 siblings, 1 reply; 2+ messages in thread

From: Emi Lu @ 2011-06-10 15:10 UTC (permalink / raw)
  To: pgsql-sql

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');

What is the command?

Thanks a lot!
Emi





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: ANY for Array value check
@ 2011-06-11 09:59  Jasen Betts <jasen@xnet.co.nz>
  parent: Emi Lu <emilu@encs.concordia.ca>
  0 siblings, 0 replies; 2+ messages in thread

From: Jasen Betts @ 2011-06-11 09:59 UTC (permalink / raw)
  To: pgsql-sql

On 2011-06-10, Emi Lu <emilu@encs.concordia.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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2011-06-11 09:59 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-06-10 15:10 ANY for Array value check Emi Lu <emilu@encs.concordia.ca>
2011-06-11 09:59 ` Jasen Betts <jasen@xnet.co.nz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox