X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E2D57563B5 for ; Mon, 21 Mar 2005 12:45:11 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 75364-04 for ; Mon, 21 Mar 2005 12:45:05 +0000 (GMT) Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by svr1.postgresql.org (Postfix) with SMTP id 76796563D5 for ; Mon, 21 Mar 2005 12:45:04 +0000 (GMT) Received: (qmail 24250 invoked from network); 21 Mar 2005 12:44:02 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.36?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 21 Mar 2005 12:44:02 -0000 Message-ID: <423EC1CE.6050701@fastcrypt.com> Date: Mon, 21 Mar 2005 07:45:02 -0500 From: Dave Cramer Reply-To: pg@fastcrypt.com Organization: Postgres International User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Guillaume Cottenceau Cc: Nico , pgsql-jdbc@postgresql.org Subject: Re: getting a sequence value References: <423EBDFA.9040507@fastcrypt.com> <87acoxuqcn.fsf@meuh.mnc.ch> In-Reply-To: <87acoxuqcn.fsf@meuh.mnc.ch> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.036 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/173 X-Sequence-Number: 12565 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 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