Using squeal-postgresql, how do I get the columns’ default values when I’m inserting based on a sub-query?
In the schema I have I’d use this SQL to create a row each in processes
and products
where the latter refers to the former:
with proc as
(insert into processes (type)
values ('the-type')
returning id)
insert into products (proc_id, eid, name)
select id, ($1 :: uuid), ($2 :: text)
from proc
trying to translate that into squeal I’ve got this so far
sql = with
(insertInto #processes
(Values_ (Default `as` #id :*
Default `as` #eid :*
Default `as` #generation :*
Set "the-type" `as` #type :*
Default `as` #extras))
OnConflictDoRaise
(Returning_ #id) `as` #proc)
(insertInto_ #products
(Subquery (select_ (undefined `as` #id :*
(param @1) `as` #eid :*
(param @2) `as` #name :*
#proc ! #id `as` #proc_id :*
undefined `as` #alloc)
(from (common #proc)))))
AFAIU there’s no way getting around giving values for all columns (right???), and that’s easy for the insert
in the with
-clause, but what do I use instead of undefined
in the lower insert
?
Originally asked here.