在网上看到别人的SQL中有个uniq函数,它的参数是一个数组。但是却报错 错误: 函数 uniq(integer[]) 不存在。
在搜索引擎中查找这个函数没有找到,最后还是在PostgreSQL官方文档中找到了,如下
uniq ( integer[] ) → integer[]
Removes adjacent duplicates. Often used with sort to remove all duplicates.
uniq('{1,2,2,3,1,1}'::integer[]) → {1,2,3,1}
uniq(sort('{1,2,3,2,1}'::integer[])) → {1,2,3}
这个函数用来消除相邻的重复项。
那为什么说找不到呢,原来它不是内置函数,需要安装intarray插件,同一篇文档最后给出了操作命令。
CREATE EXTENSION intarray;
select uniq(array[1,1,2]);
uniq
-------
{1,2}
(1 行记录)
select uniq(array[1,2,1]);
uniq
---------
{1,2,1}
(1 行记录)

2720

被折叠的 条评论
为什么被折叠?



