such request

WITH insert_foo AS (INSERT INTO analiz_create (name, template_id) VALUES ( (SELECT nam.name FROM vgok_site.a_template_name nam, vgok_site.a_template TEMP WHERE TEMP.name_id = nam.id AND TEMP.id = $zn_template), $zn_template) returning id) INSERT INTO analiz_data ( elem_id, analiz_id, value) VALUES (84, (SELECT id FROM insert_foo), $id_lvl) RETURNING id 

those. First, I create an entry in the table - header, and then using the resulting id, I write down the value in the child table, using the received id.

if I make a retour at the end, then I’ll get an ID from the table-daughter, but I want to get an ID from the cap

    1 answer 1

    in this case you need to write not

    RETURNING id

    but

    RETURNING analiz_id