sql - postgresql insert or create with temp table merge -
i have 3 tables: a
b
, c
. b
temp table
created output of csv
. goal copy necessary values b
a
but 1 of attributes has created or selected c
.
so far have
with table_c_data ( insert table_c (id) select table_c_id table_b b not exists (select * table_c c b.table_c_id = c.id) returning * ) insert table_a (w,x,y,z) select table_c.id, x, y, z table_b inner join table_c_data table_c on table_b.table_c_id = table_c.id;
but having trouble figuring out how have original table_c_data
return if record does existing. (before added in where
clause specifying existing query ran expected, trying handle uniquness constraints have check whether record exists first)
Comments
Post a Comment