在网上看到别人的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插件,同一篇文档最后给出了操作命令。
CREATEEXTENSION intarray;selectuniq(array[1,1,2]);uniq-------{1,2}(1行记录)selectuniq(array[1,2,1]);uniq---------{1,2,1}(1行记录)