[英]pgsql merge two json arrays
我必须从表中选择两种类型的结果集并将它们合并到单个 json 数组中,例如
select col1,col2,col3 from table 1 order by col3 where col1< 2
union all
select col1,col2,col3 from table 1 order by col1 where colo = 3
它说语法错误我相信由于 order by。
我需要在 json 数组中返回它,所以我正在尝试这样
SELECT ( SELECT json_agg(row)
FROM (
select col1,col2,col3 from table 1 order by col3 where col1< 2 ) row)
UNION ALL
SELECT (SELECT json_agg(row)
FROM (
select col1,col2,col3 from table 1 order by col1 where colo = 3
) row)
它停用了两个 json 数组,即很明显,我如何在单个数组中制作它
谢谢,
在 UNION 之后做聚合:
select json_agg(t)
from (
(select col1,col2,col3 from table1 order by col3 where col1< 2)
union all
(select col1,col2,col3 from table1 order by col1 where colo = 3)
) t
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.