postgresql postgres 中带有不同字符串的 string_agg 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24785084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:32:53 来源:igfitidea点击:
issue with string_agg with distinct in postgres
提问by user1298426
I am getting error for below query. Basically to use ||
& distinct
together.
我收到以下查询错误。基本上与||
&distinct
一起使用。
select string_agg( 'pre' || distinct user.col, 'post')
It works fine like this
它像这样工作正常
select string_agg( 'pre' || user.col, 'post')
& this
& 这
select string_agg(distinct user.col, 'post')
回答by Clodoaldo Neto
select string_agg(distinct 'pre' || user.col, 'post')
As the above will deny the use of an index in the distinct
aggregation take the 'pre'
out
由于上面将拒绝在distinct
聚合中使用索引'pre'
取出
select 'pre' || string_agg(distinct user.col, 'postpre')