Fork me on GitHub
#honeysql
<
2022-05-15
>
Ho0man07:05:14

Hi everyone, is there a way in honey and psqlh that I could do these two queries in a single statement - assuming these are my tables user (id, login, password, name) and dealer (id, user_id) :

WITH rows AS (
    INSERT INTO "user"
        (login, password, name)
    VALUES
        ('dealer1', 'jygbjybk', 'Dealer 1')
    RETURNING id
)
INSERT INTO dealer (user_id)
    SELECT id
    FROM rows;
SELECT currval('dealer_id_seq');
I want to insert in the user table and use the returning id from that to insert the dealer in one statement. Were using honeysql from versions prior to 2. Thanks