ERROR: function group_concat(character varying) does not exist

Database:PostgreSQL 9.4.24
报错信息显示:函数 group_concat(character varying) 不存在,通过查资料发现。

PostgreSQL里面没有group_concat函数(MySQL里面有—),为了使用group_concat这一功能,我们可以用array_agg 和
array_to_string 取而代之。array_agg 和 array_to_string同样可以用于其他数据库,用于达到group_concat这一功能。

string_agg函数可以替代array_agg 和 array_to_string的组合。

STRING_AGG(DISTINCT CASE WHEN party_role_type = 0 THEN role_name END, ',') AS "zero_party"
**结论Conclusion**

There is no function like group_concat available in PostgreSQL which was available in MySQL, instead of using this function we are using array_agg and array_to_string function. Array_agg and array_to_string function will work same as group_concat function work in other databases. We can also use string_agg function in PostgreSQL.

Example

分隔符separator可以自己选
select address, array_to_string(array_agg(name order by name), '%') from group_concat group by address;
select address, array_to_string(array_agg(name order by name), ',') from group_concat group by address;
# 若要组内去重
select address, array_to_string(array_agg(distinct name order by name), ',') from group_concat group by address;

https://www.educba.com/postgresql-group_concat/

PostgreSQL查看版本信息

https://blog.csdn.net/kmblack1/article/details/78721653

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值