【发布时间】:2017-03-30 21:41:18
【问题描述】:
我在 postgres 中有一个包含重复值的数组。例如:
SELECT cardinality(string_to_array('1,2,3,4,4', ',')::int[]) as foo
=> "foo"=>"5"
我想获取独特的元素,例如:
SELECT cardinality(uniq(string_to_array('1,2,3,4,4', ',')::int[])) as foo
=> -- No function matches the given name and argument types. You might need to add explicit type casts.
我可以在不使用 UNNEST 的情况下在 postgres 中获取数组的唯一元素吗?
【问题讨论】:
-
UNNEST 有什么问题?使用 UNNEST,您将能够选择 DISTINCT 并完成工作..
-
intarraymodule中有一个特定的uniq(int[])函数,但除此之外,你必须使用unnest()。
标签: arrays postgresql unique postgresql-9.4