Thom
Thom

Reputation: 553

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

Upvotes: 0

Views: 34

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269703

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

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

Upvotes: 1

Related Questions