Re: getting a sequence value - Mailing list pgsql-jdbc

From Dave Cramer
Subject Re: getting a sequence value
Date
Msg-id 423EC1CE.6050701@fastcrypt.com
Whole thread Raw
In response to Re: getting a sequence value  (Guillaume Cottenceau <gc@mnc.ch>)
Responses Re: getting a sequence value
List 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


pgsql-jdbc by date:

Previous
From: Roland Walter
Date:
Subject: Re: getting a sequence value
Next
From: Guillaume Cottenceau
Date:
Subject: Re: getting a sequence value