Hey! In SQLDelight I was wondering if it was possible to get the last inserted rowid of another table, I remember doing something like this with a function within a grouped statement but I can't seem to redo it with Postgres.
Thank you!
a
Arjan van Wieringen
02/01/2024, 5:23 AM
“INSERT INTO persons (lastname,firstname) VALUES ('Smith', 'John') RETURNING id;”?
t
Tech
02/01/2024, 5:38 AM
Copy code
insert {
// last_insert_rowid()
val empId = INSERT INTO employees(id) VALUES (DEFAULT) RETURNING id;
INSERT INTO Company(employeeId) VALUES (empId);
}
Basically I need to pass the id of one inserted object to another in the same transaction block
Tech
02/01/2024, 5:38 AM
i know it’s possible but it doesn’t seem like the SQLite syntax works with Postgres
insert:
WITH new_employee AS (
INSERT INTO employee(name) VALUES (?) RETURNING employee_id
),
new_company_employee AS (
INSERT INTO company(employee_id)
SELECT employee_id
FROM new_employee
ON CONFLICT DO NOTHING
RETURNING *
)
SELECT * FROM new_company_employee JOIN new_employee USING (employee_id);