postgres select all rows that has any of list strings in a varchar[] column

Viewed 567
create table Table1(id bigserial not null primary key, names VARCHAR(256)[]);

insert into Table1(names) values('{name1,name2}');

insert into Table1(names) values('{name3,name4}');

select * from Table1 where names @> '{name1}';

Result

id | name

---+-----

1  | {name1,name2}

I want to be able to provide list of varchar like name1, name3 and select query should return both rows

1 Answers

You can use the overlaps operator &&:

where names && array['name1', 'name3']::varchar[];
Related