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

Re: Returning generated id after a transaction.

From: Guillaume Henriot <henriotg(at)gmail(dot)com>
To: Bartosz Dmytrak <bdmytrak(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Returning generated id after a transaction.
Date: 2012-04-23 15:28:31
Message-ID: CALJcmg9mz4=k50poCfavYmML=tbVreAmOV8QGd33Sk=oVK1mkw@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Just one quick question again about my first problem, is that a limitation
that code between begin and commit can't send back the id, or was it just a
problem about my code ?

Le 23 avril 2012 17:17, Guillaume Henriot <henriotg(at)gmail(dot)com> a écrit :

> 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(at)gmail(dot)com> a écrit :
>
> 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: Jim BlizardDate: 2012-04-23 17:46:37
Subject: Re: logging pg_dump results in windows 7
Previous:From: Guillaume HenriotDate: 2012-04-23 15:17:23
Subject: Re: Returning generated id after a transaction.

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