如何获取数组包含任何字段数组元素的所有行
How to fetch all rows where an array contains any of the fields array elements
我有一个 table,其中有一列 video_ids
,它是 bigint[]
类型。我想找到在 select 语句中传递数组中任何元素的所有行。因此,如果我有一行包含如下所示的 video_ids
字段:
{9529387, 9548200, 9579636}
如果我传递一个包含任何此 video_ids
的数组,我想获取它。我想我会用任何东西来做,但我不确定如何在 SQL 中做到这一点,我试过这个:
select id, finished, failed, video_ids, invoiced_video_ids, failed_video_ids
from video_order_execution
where order_ids = any(
'{9548200, 11934626, 9579636, 11936321, 11509698, 11552728, 11592106, 11643565, 11707543, 11810386, 11846268}'
::bigint[]);
如果我这样做会出现错误:
ERROR: operator does not exist: bigint[] = bigint Hint: No operator
matches the given name and argument types. You might need to add
explicit type casts.
我怎样才能做出这样的声明来满足我的需要?
如果 2 个操作数有任何共同项,请使用运算符 &&
which returns true
:
select id, finished, failed, video_ids, invoiced_video_ids, failed_video_ids
from video_order_execution
where order_ids &&
'{9548200, 11934626, 9579636, 11936321, 11509698, 11552728, 11592106, 11643565, 11707543, 11810386, 11846268}'::bigint[];
我有一个 table,其中有一列 video_ids
,它是 bigint[]
类型。我想找到在 select 语句中传递数组中任何元素的所有行。因此,如果我有一行包含如下所示的 video_ids
字段:
{9529387, 9548200, 9579636}
如果我传递一个包含任何此 video_ids
的数组,我想获取它。我想我会用任何东西来做,但我不确定如何在 SQL 中做到这一点,我试过这个:
select id, finished, failed, video_ids, invoiced_video_ids, failed_video_ids
from video_order_execution
where order_ids = any(
'{9548200, 11934626, 9579636, 11936321, 11509698, 11552728, 11592106, 11643565, 11707543, 11810386, 11846268}'
::bigint[]);
如果我这样做会出现错误:
ERROR: operator does not exist: bigint[] = bigint Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
我怎样才能做出这样的声明来满足我的需要?
如果 2 个操作数有任何共同项,请使用运算符 &&
which returns true
:
select id, finished, failed, video_ids, invoiced_video_ids, failed_video_ids
from video_order_execution
where order_ids &&
'{9548200, 11934626, 9579636, 11936321, 11509698, 11552728, 11592106, 11643565, 11707543, 11810386, 11846268}'::bigint[];