Skip to content
Advertisement

Update returning * and select result as rows

I want to run a few updates in a single query returning *, and select the output as rows. I currently have

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;

That does what I’m looking for but feels like it could be improved. I almost got it working like this

select * from foo, bar

but it displays as a single row not two separate rows

Advertisement

Answer

I think you simply want union all (or perhaps `union1):

select foo.*
from foo
union all
select bar.*
from bar;
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement