Skip site navigation (1) Skip section navigation (2)

Re: Returning generated id after a transaction.

From: Bartosz Dmytrak <bdmytrak(at)gmail(dot)com>
To: Guillaume Henriot <henriotg(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Returning generated id after a transaction.
Date: 2012-04-21 08:26:31
Message-ID: CAD8_Ucb=mbrSuhAWbMtjdY2k6c3rr4NPLzaxQKCArR9cde+R3g@mail.gmail.com (view raw or flat)
Thread:
Lists: 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

In response to

Responses

pgsql-novice by date

Next:From: Guillaume HenriotDate: 2012-04-23 15:17:23
Subject: Re: Returning generated id after a transaction.
Previous:From: Bartosz DmytrakDate: 2012-04-20 21:08:18
Subject: Re: Returning generated id after a transaction.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group