首页 > 解决方案 > 更新返回 * 并选择结果作为行

问题描述

我想在返回 * 的单个查询中运行一些更新,并将输出选择为行。我目前有

with
  foo as (update table set .. where id = $1 retuning *),
  bar as (update table set .. where id = $2 retuning *)
select * from table where id = $1 or id = $2;

这正是我想要的,但感觉它可以改进。我几乎让它像这样工作

select * from foo, bar

但它显示为单行而不是两个单独的行

标签: sqlpostgresql

解决方案


我认为您只是想要union all(或者可能是`union1):

select foo.*
from foo
union all
select bar.*
from bar;

推荐阅读