gpt4 book ai didi

postgresql - 在postgresql中仅查找两个字符串数组之间的非匹配元素的最佳方法是什么

转载 作者:行者123 更新时间:2023-11-29 12:13:50 25 4
gpt4 key购买 nike

目前我发现的是

select ARRAY(
select unnest(ARRAY[ 'a', 'b', 'c' ])
except
select unnest(ARRAY[ 'c', 'd', 'e' ])
)

我们可以这样做以仅查找两个字符串数组之间的非匹配元素。

还有其他最好的方法吗?

像整数数组一样,我们可以这样做

SELECT int[1,2,3] - int[2,3]

最佳答案

select array_agg(e order by e)
from (
select e
from
(
select unnest(array[ 'a', 'b', 'c' ])
union all
select unnest(array[ 'c', 'd', 'e' ])
) u (e)
group by e
having count(*) = 1
) s

关于postgresql - 在postgresql中仅查找两个字符串数组之间的非匹配元素的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15067128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com