3 ms·
Upsert is already possible in a single statement, though a bit unwieldy. create table people (uuid varchar, name varchar); with new_rows as (select (un
by ef4 13y ago
Upsert is already possible in a single statement, though a bit unwieldy.
create table people (uuid varchar, name varchar);
with new_rows as (select (unnest(ARRAY[('xxx','John Smith'), ('yyy', 'Ben Bitdiddle')]::people[])).*), updated as (UPDATE people SET name=new_rows.name FROM new_rows WHERE people.uuid=new_rows.uuid RETURNING people.uuid) insert into people select new_rows.* from new_rows left join updated using (uuid) where updated.uuid is null;