Re: Last Insert

From: Steve Lane <slane(at)fmpro(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Last Insert
Date: 2002-03-13 21:46:27
Message-ID: B8B524D3.A06D%slane@fmpro.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/13/02 10:58 AM, "Stephan Szabo" <sszabo(at)megazone23(dot)bigpanda(dot)com> wrote:

> On Wed, 13 Mar 2002, Marcelo Pereira wrote:
>
>> Hello All,
>>
>> I have two tables, the first is parental and the second is a child of the
>> first.
>>
>> Ex.:
>>
>> create table first (id SERIAL, descrip CHAR(20));
>> create table second (id INTEGER references first(id), state CHAR(2));
>>
>> I have `all' the values to make the inserts in the two tables (ie, descrip
>> and state), so I `would' use:
>>
>> INSERT into first (descrip) values ($descr);
>> INSERT into second (id,state) values (?????????,$state);
>
> currval('first_id_seq') should get you the last sequence value given to
> your session.

I havw a question. Is this reliable even in a connection-pooled environment?
I've always been a little scared of any possible concurrency issues here so
I usually look at the result of the INSERT to get the oid, then use the oid
to query for my key. Am I being too cautious?

-- steve

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message thiemo 2002-03-13 21:47:01 Re: [JDBC] Fwd: DBvisualizer on MacOS X
Previous Message Ron Snyder 2002-03-13 21:29:11 Unexplainable slow down...