It doesn't have to be via a CTE if there's a simpler way. insert a single user, get the ID of that new row, and use that ID when inserting multiple posts? Is there a way I can combine the two? i.e. I can also insert a user and a single post referencing that author using a common table expression: WITH john AS ( In postgres I can insert multiple rows using VALUES: INSERT INTO Id UUID PRIMARY KEY DEFAULT uuid_generate_v4 (),Īuthor_user_id UUID NOT NULL REFERENCES users (id), I want to insert a single row into the "parent" table, then use the generated ID of that row as a foreign key when I insert multiple rows into the "children" table.įor example, say I have this schema: CREATE TABLE users (
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |