有没有办法让我从子查询返回多个列,或者至少返回一个作为我需要的所有列的 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)
Run Code Online (Sandbox Code Playgroud)
在哪里$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)
Run Code Online (Sandbox Code Playgroud)
环顾四周后,似乎这row_to_json
应该对我有用。但是,我不确定在这种情况下它应该如何工作:
select r.*,
row_to_json(select status,
start_time, end_time
from builds
where repo …
Run Code Online (Sandbox Code Playgroud) postgresql ×1