SQL postgres 中 LISTAGG 的等价物是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29557563/
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-09-01 03:30:25  来源:igfitidea点击:

What's the equivalent for LISTAGG in postgres?

sqlpostgresqlstring-aggregationlistagg

提问by cy221

I have to replace the Oracle driver with the newest postgres.

我必须用最新的 postgres 替换 Oracle 驱动程序。

Postgres doesn't know the function LISTAGG. I have to concat values by comma separated.

Postgres 不知道函数 LISTAGG。我必须用逗号分隔来连接值。

What's the equivalent for the Oracle function LISTAGG in Postgres?

Postgres 中 Oracle 函数 LISTAGG 的等价物是什么?

Thanks.

谢谢。

回答by Vivek S.

The equivalent function in Postgres is string_agg()

Postgres 中的等效函数是 string_agg()

select string_agg(col,',') from my_table

string_agg: input values concatenated into a string, separated by delimiter

string_agg: 输入值连接成一个字符串,由分隔符分隔

回答by Akash Reddy

From Postgres 9.0 or later, I believe you could do something like this:

从 Postgres 9.0 或更高版本开始,我相信您可以执行以下操作:

SELECT c_id, STRING_AGG(c_grp_id, ',' ORDER BY c_grp_id) AS group_ids 
FROM c_grp_at 
GROUP BY c_id