Re: getting a sequence value

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Guillaume Cottenceau <gc(at)mnc(dot)ch>
Cc: Nico <nicohmail-postgresql(at)yahoo(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: getting a sequence value
Date: 2005-03-21 12:45:02
Message-ID: 423EC1CE.6050701@fastcrypt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Guillaume,

No it can't be wrong from the database's point of view, now what happens
in java is another problem

Here's how it works, in principle anyway.

The last value of each sequence which has been generated using nextval
is stored in the connections session memory.
so when you use the SAME connection to retrieve currval it will retrieve
that value.

If you get a different connection, or store it in a shared value in your
java then it doesn't work.

Dave

Guillaume Cottenceau wrote:

>Dave Cramer <pg 'at' fastcrypt.com> writes:
>
>
>
>>2)
>>allow the insert to go through
>>select currval('public."tblTable1_FieldID_seq"'::text)
>>and then use this to insert into table 2
>>
>>FYI currval does the "right" thing. It is guaranteed to be the value
>>your connection retrieved from the sequence.
>>
>>
>
>Which can be wrong in case of multithreaded applications without
>synchronization over the two requests, if I'm correct.
>
>
>

--
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Guillaume Cottenceau 2005-03-21 12:52:46 Re: getting a sequence value
Previous Message Roland Walter 2005-03-21 12:39:23 Re: getting a sequence value