Re: Returning generated id after a transaction. - Mailing list pgsql-novice

From Bartosz Dmytrak
Subject Re: Returning generated id after a transaction.
Date
Msg-id CAD8_Ucb=mbrSuhAWbMtjdY2k6c3rr4NPLzaxQKCArR9cde+R3g@mail.gmail.com
Whole thread Raw
In response to Re: Returning generated id after a transaction.  (Guillaume Henriot <henriotg@gmail.com>)
Responses Re: Returning generated id after a transaction.  (Guillaume Henriot <henriotg@gmail.com>)
List pgsql-novice
Hi,
there is option no. 4 (kind of extended WITH)

WITH 
inserted_row AS (
INSERT INTO "tblParent" ("RowValue")
VALUES ('2012-01-01'::date)
RETURNING *
), 
updated_row AS (UPDATE "tblChild"
SET "ParentRowId" = (SELECT "RowId" FROM inserted_row)
WHERE "RowId" = 123 --whatever You need
)

SELECT "RowId" FROM inserted_row;

I missed it in previous post.
This could be part of function (SELECT statement should be modified) or ad-hoc query.

Regards,
Bartek


pgsql-novice by date:

Previous
From: Bartosz Dmytrak
Date:
Subject: Re: Returning generated id after a transaction.
Next
From: Guillaume Henriot
Date:
Subject: Re: Returning generated id after a transaction.