更新/注意
pg_typeof()我的目标列下面的答案是“regtype”,而不是“text”......
所以下面这个人为的例子是一个红鲱鱼。下面的@richyen 正确回答了它。对于那些表格不是文本的人,需要转换为文本,这是下面@a_horse_with_no_name 接受的答案
从表myschema.thing:
id | fruit | color | owner_id
---+--------+--------+---------
1 | apple | red | 100
2 | banana | yellow | 100
3 | tomato | red | 500
4 | grape | purple | 200
我试图得到结果:
colors
------------------
red,yellow,purple
基于此页面:https ://www.postgresql.org/docs/11/functions-string.html
我试过这个:
select concat_ws(',', distinct(color)) as colors
from myschema.thing
但它不起作用。我哪里错了?提前致谢。