我有以下一组表格:
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的堆栈问题.
最佳答案
使用 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);
关于sql - 为从 Postgres 中提取的列列表中的值创建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40415894/