CREATE TABLE TEST(id int, description varchar(100));
INSERT INTO TEST VALUES (1, 'The quick brown fox'),
(1, 'This is a test to check for data'),
(1, 'This is just another test checking data'),
(2, 'Data set 2'),
(2, 'This is a test for data set 2'),
(2, 'Quickest fox catches the worms')
我有一个查询,我正在使用array_agg函数将所有描述放在一个字段上。由于大小限制,我试图只带回每个描述的前三个字符。
select id, array_agg(id||', ') as ids,
array_agg(description||', ') as description
from test
group by id
我试图使用长度函数,但看不到如何限制数组中的每个值。