2012-03-27 92 views
2

是否有可能使一个大阵列从类似的查询:如何使从一个SELECT返回一个数组的多行

select 
array_append(ARRAY[0], console_id) 
from archive_sessions 
where tournament_id = 14817 

group by试过,但我有它,它使用console_id还是超过1排。

如何在此查询中初始化一个空的ARRAY[]

回答

3

你想array_agg

select array_agg(console_id) as consoles from archive_sessions where tournament_id = 14817 
+0

我见过这个功能,但为什么我没有尝试它-1对我来说+1对你来说 – 2012-03-27 19:28:20

3

如果查询只返回进入阵列列(S),使用ARRAY constructor

SELECT ARRAY(SELECT console_id FROM archive_sessions 
      WHERE tournament_id = 14817) AS console_arr; 

这通常是array_agg()为快简单的情况。