Postgres 数组在 where 子句中查找多个值
Postgres array lookup multiple values in where clause
我有以下 table 数据
create table stud(key int, person text, subject_id int[]);
insert into stud select 1,'Alex',array[2,7,9];
insert into stud select 2,'Peter',array[4,9,12];
insert into stud select 3,'Tokaver',array[8];
insert into stud select 4,'Machel',array[11,15];
Table 长相
我可以在喜欢
的地方过滤单个subject_id
select * from stud where 9=any(subject_id)
我们如何在 where 子句 like
中过滤多个 subject_id
select * from stud where (8,9) in any(subject_id)
您可以对数组使用重叠运算符 &&
:
select * from stud
where array[8,9] && subject_id
我有以下 table 数据
create table stud(key int, person text, subject_id int[]);
insert into stud select 1,'Alex',array[2,7,9];
insert into stud select 2,'Peter',array[4,9,12];
insert into stud select 3,'Tokaver',array[8];
insert into stud select 4,'Machel',array[11,15];
Table 长相
我可以在喜欢
的地方过滤单个subject_idselect * from stud where 9=any(subject_id)
我们如何在 where 子句 like
中过滤多个 subject_idselect * from stud where (8,9) in any(subject_id)
您可以对数组使用重叠运算符 &&
:
select * from stud
where array[8,9] && subject_id