sql >> Base de Datos >  >> RDS >> PostgreSQL

usando las identificaciones devueltas de insertar en, para la inserción de registros con clave externa

with s(name, distance) as (
    values ('archer goblin', 10), ('dragon', 50)
), the_ids as (
    insert into monster(name) 
    select name
    from s
    returning id, name
)
insert into ranged_monster (id_monster, distance)
select id, distance
from
    s
    inner join
    the_ids using (name)