pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Guillaume Cottenceau <gc@mnc.ch>
Cc: Nico <nicohmail-postgresql@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: getting a sequence value
Date: Mon, 21 Mar 2005 07:45:02 -0500
Message-ID: <423EC1CE.6050701@fastcrypt.com> (raw)
In-Reply-To: <87acoxuqcn.fsf@meuh.mnc.ch>
References: <d1mb4u$1j89$1@news.hub.org>
	<423EBDFA.9040507@fastcrypt.com>
	<87acoxuqcn.fsf@meuh.mnc.ch>

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




view thread (9+ messages)  latest in thread

Message-ID: <423EC1CE.6050701@fastcrypt.com>
Permalink:  ../423EC1CE.6050701@fastcrypt.com/
Also on:    postgresql.org/message-id/423EC1CE.6050701@fastcrypt.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: pg@fastcrypt.com, gc@mnc.ch, nicohmail-postgresql@yahoo.com
  Subject: Re: getting a sequence value
  In-Reply-To: <423EC1CE.6050701@fastcrypt.com>
  References: <d1mb4u$1j89$1@news.hub.org> <423EBDFA.9040507@fastcrypt.com> <87acoxuqcn.fsf@meuh.mnc.ch> <423EC1CE.6050701@fastcrypt.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox