Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个充满记录的表和一个数组列,现在我想获取该列中所有(唯一)值的列表。获得它的最佳方法是什么?
我试着玩弄unnest,array_agg但string_agg没有得到任何地方......
unnest
array_agg
string_agg
(使用 Postgres 9.2)
select distinct unnest(a) from (values (array[1, 2]), (array[2, 3]) ) s(a); unnest -------- 3 1 2
或聚合在一个数组中:
select array_agg(a order by a) from ( select distinct unnest(a) as a from (values (array[1, 2]), (array[2, 3]) ) s(a) ) s; array_agg ----------- {1,2,3}