有什么方法可以让我从子查询中返回多个列,或者至少返回一个列,该列是我需要的所有列的 JSON 对象?
这是一个有效的工作查询:
select r.*,
(select status
from builds
where repo = r.id
and branch = 'master'
order by id desc
limit 1)
from repos r
where id = any($1)
$1
id数组在哪里
但我想返回的不仅仅是表中的状态列builds
:
select r.*,
(select status, start_time, end_time
from builds
where repo = r.id
and branch = 'master'
order by id desc
limit 1)
from repos r
where id = any($1)
环顾四周后,它似乎row_to_json
对我有用。但是,我不确定在这种情况下它应该如何工作:
select r.*,
row_to_json(select status,
start_time, end_time
from builds
where repo = r.id
and branch = 'master'
order by id desc
limit 1) as build
from repos r
where id = any($1)
我正进入(状态
syntax error at or near "select"
不要让自己的生活变得艰难,使用横向连接: