Re: Returning generated id after a transaction.

Поиск
Список
Период
Сортировка
От Bartosz Dmytrak
Тема Re: Returning generated id after a transaction.
Дата
Msg-id CAD8_Ucb=mbrSuhAWbMtjdY2k6c3rr4NPLzaxQKCArR9cde+R3g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Returning generated id after a transaction.  (Guillaume Henriot <henriotg@gmail.com>)
Ответы Re: Returning generated id after a transaction.  (Guillaume Henriot <henriotg@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Bartosz Dmytrak
Дата:
Сообщение: Re: Returning generated id after a transaction.
Следующее
От: Guillaume Henriot
Дата:
Сообщение: Re: Returning generated id after a transaction.