本文介绍了从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]
。
I wanted to get the array from the result as: [t,f,t]
in Postgres.
请参考前面的堆栈问题在。
Please have reference to the earlier stack question over here.
推荐答案
使用:
SELECT ARRAY [bool_or(column_a)
, bool_or(column_b)
, bool_or(column_c)] AS arr_abc
FROM tbl
WHERE id IN (1,2);
这篇关于从Postgres中提取的列列表中为值创建数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!