PostgreSQL查询以逗号分隔列表的形式返回结果 [英] PostgreSQL query to return results as a comma separated list
本文介绍了PostgreSQL查询以逗号分隔列表的形式返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设您有一个来自表的 SELECT ID
查询(实际情况是一个复杂的查询),它确实会返回几个结果。
Let say you have a SELECT id from table
query (the real case is a complex query) that does return you several results.
问题是如何在逗号分隔的单行中获取所有 id
?
The problem is how to get all id
return in a single row, comma separated?
推荐答案
从表中选择string_agg(id :: text,',')
需要PostgreSQL 9.0,但这不是问题。
Requires PostgreSQL 9.0 but that's not a problem.
这篇关于PostgreSQL查询以逗号分隔列表的形式返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文