For a bulk insert, I have a foreign reference value. As part of the insert, I'd like to return both the reference and corresponding id's of the newly created records in order to create a mapping record in another system.
Using "RETURNING" works fine for the target table. Other than creating a dummy column in the target table, is there anyway to achieve what I'm trying to do?
Definitely do not want to do row-by-row processing.
NOTE: Currently using version 10.7
In my sample code, I tried "returning id, source.ref", but obviously this isn't supported.
create table test( id serial primary key, name varchar);
insert into test( name)
select source.name
from ( values('refa', 'name a'), ('refb', 'name b'), ('refc', 'name c') ) source(ref, name)
returning id --, source.ref