在postgres中消除重复的数组值 [英] eliminate duplicate array values in postgres
本文介绍了在postgres中消除重复的数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类型为 bigint
的数组,如何删除该数组中的重复值?
I have an array of type bigint
, how can I remove the duplicate values in that array?
例如: array [1234,5343,6353,1234,1234]
我应该得到 array [1234,5343,6353,...]
我测试了示例 SELECT uniq(sort ('{1,2,3,2,1}':: int []))
,但它不起作用。
I tested out the example SELECT uniq(sort('{1,2,3,2,1}'::int[]))
in the postgres manual but it is not working.
推荐答案
我也遇到了同样的问题。但是在我的情况下,数组是通过 array_agg
函数创建的。幸运的是,它允许聚合 DISTINCT 值,例如:
I faced the same. But an array in my case is created via array_agg
function. And fortunately it allows to aggregate DISTINCT values, like:
array_agg(DISTINCT value)
这对我有用。
这篇关于在postgres中消除重复的数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文