我希望能够获取与每个
id
相关联的所有单词数组。以下是示例数据:id | words
---|------------------
1 | {foo,bar,zap,bing}
2 | {foo}
1 | {bar,zap}
2 | {bing}
1 | {bing}
2 | {foo,bar}
输出:
id | allwords
---|--------------------------------
1 | {foo,bar,zap,bing,bar,zap,bing}
2 | {foo,bing,foo,bar}
我尝试使用array_agg(words)
,但出现以下错误:
ERROR: could not find array type for data type text[]
这里应该采取什么正确的方法呢?我想要所有单词,包括重复的。
DISTINCT
:array_agg(DISTINCT w)
。 - jpmc26