簡體   English   中英

Postgres數組在where子句中查找多個值

[英]Postgres array lookup multiple values in where clause

我有下表的數據

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];

表外觀

在此處輸入圖像描述

我可以在類似的地方過濾單個subject_id

select * from stud where 9=any(subject_id)

我們如何在 where 子句中過濾多個 subject_id,例如

select * from stud where (8,9) in any(subject_id)

演示:db<>小提琴

您可以將重疊運算符&&用於 arrays:

select * from stud 
where array[8,9] && subject_id

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM