Re: Currval question and confusion

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Kumar S <ps_postgres(at)yahoo(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Currval question and confusion
Date: 2005-03-05 20:05:23
Message-ID: 20050305200523.GA70847@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Sat, Mar 05, 2005 at 11:40:47AM -0800, Kumar S wrote:

> Now 3 people have simultaneously issued insert
> statements. After some time while the second process
> is still filling table 1 and enters table2 the currval
> position has been changed. Then will I be assigning a
> wrong FK in table2 and table3.

Are you asking if there's a problem, or are you saying you've
observed a problem? currval() is documented to return the most
recently obtained value *in the current connection*, so if each
process uses a different connection then you shouldn't have a
problem. Connection pooling could interfere with this, however,
if it allows queries from different processes to be interleaved on
the same connection. In that case you could call nextval() prior
to the inserts and remember the key values on the client side.

http://www.postgresql.org/docs/8.0/interactive/functions-sequence.html
http://www.postgresql.org/files/documentation/faqs/FAQ.html#4.11.3

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message John Phillips 2005-03-05 20:52:03 Need some install help .....pgsql8.0.1 on Suse Linux 9.2 pro
Previous Message Kumar S 2005-03-05 19:40:47 Currval question and confusion