2016-11-04 30 views
2
提取列的列表

我有以下一組表的創建數值數組:從Postgres的

id column_a column_b column_c 
1  t   f   t 
2  t   f   f 
3  f   t   f 

當被詢問:

SELECT bool_or(column_a) AS column_a 
    , bool_or(column_b) AS column_b 
    , bool_or(column_c) AS column_c 
FROM tbl 
WHERE id IN (1,2); 

給出結果爲:

column_a column_b column_c 
t   f   t 

我想從Postgres的結果中得到這個數組:[t,f,t]

請參考here之前的堆棧問題。

回答

2

使用ARRAY constructor

SELECT ARRAY [bool_or(column_a) 
      , bool_or(column_b) 
      , bool_or(column_c)] AS arr_abc 
FROM tbl 
WHERE id IN (1,2);