I'm trying to insert an Address into the adresses table and refer to a User already registered without Address in the user table, through the _id that is generated when I enter an Address. Return this _id and insert it into the adresses_id column of the User that has cpf equal to that of the User that will receive this Address.
WITH new_adresses AS (
INSERT INTO adresses (cep, street, neighborhood, city, state, number_house, complement)
VALUES ('11222333', 'Rua Qualquer', 'Bairro', 'Cidade', 'ES', 777, 'Ed. Edifício')
RETURNING _id)
INSERT INTO users (adresses_id)
VALUES (SELECT _id FROM new_adresses)
WHERE cpf = '111.222.333-00'
I'm not able to perform the insert this way. The following error message is displayed:
ERROR: syntax error at or near "SELECT"
Posição: 281