Re: Returning generated id after a transaction.
| От | Guillaume Henriot |
|---|---|
| Тема | Re: Returning generated id after a transaction. |
| Дата | |
| Msg-id | CALJcmg-KRyRACYTgx_qSN8J9rBpF2UU48GsxKULVbpV3Tj5K9w@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: Returning generated id after a transaction. (Bartosz Dmytrak <bdmytrak@gmail.com>) |
| Ответы |
Re: Returning generated id after a transaction.
|
| Список | pgsql-novice |
Thank you so much for these examples, I tryed the 4th one for it's easiness and it works perfectly ! I'm probably going to replace it with your no.2 example as soon as I have time as I do agree with you about data and application logic.
Thanks again,
Guillaume
Le 21 avril 2012 10:26, Bartosz Dmytrak <bdmytrak@gmail.com> a écrit :
Hi,there is option no. 4 (kind of extended WITH)WITHinserted_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 по дате отправления: