Redshift SQL 数组相交

问题描述 投票:0回答:1

Redshift中有数组相交函数,或者有好的方法吗?

例如在雪花中它是:


    SELECT array_intersection(ARRAY_CONSTRUCT('A', 'B'), ARRAY_CONSTRUCT('B', 'C'));

    Output: ["B"]

文档似乎没有这个功能或任何我能找到的远程有用的东西。

如果不需要的话,我会避免取消数组的嵌套来加入。

有什么想法吗?

sql arrays amazon-redshift intersection intersect
1个回答
0
投票

据我所知,我认为它没有任何类似的内置功能。您提到不想解除嵌套,但我认为这将是您在 Redshift 上最好(也是唯一)的选择:

create temp table rs_arrays(
    id int,
    val super
);

insert into rs_arrays (id, val)
select 1, array('a', 'b')
union
select 2, array('b', 'c');

with cte AS (
    SELECT rsa.*,
       v
FROM rs_arrays rsa, rsa.val v
)

select distinct c1.v
from cte c1
inner join cte c2
    ON c1.v = c2.v
    and c1.id != c2.id
© www.soinside.com 2019 - 2024. All rights reserved.