Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 96EBD4765AA; Thu, 6 Jun 2002 12:35:45 -0400 (EDT) Received: from bast.unixathome.org (bast.unixathome.org [216.187.105.150]) by postgresql.org (Postfix) with ESMTP id 8D1074765E8; Thu, 6 Jun 2002 12:34:12 -0400 (EDT) Received: from wocker (wocker.unixathome.org [192.168.0.99]) by bast.unixathome.org (Postfix) with ESMTP id D685F3F28; Thu, 6 Jun 2002 12:35:24 -0400 (EDT) From: "Dan Langille" Organization: DVL Software Limited To: Nicolas Nolst Date: Thu, 6 Jun 2002 12:33:54 -0400 MIME-Version: 1.0 Subject: Re: [GENERAL] performance issue using DBI Reply-To: dan@langille.org Cc: pgsql-admin@postgresql.org, pgsql-general@postgresql.org References: In-reply-to: <1023380046.26291.2977.camel@linda> X-mailer: Pegasus Mail for Windows (v4.01) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body Message-Id: <20020606163524.D685F3F28@bast.unixathome.org> X-Archive-Number: 200206/34 X-Sequence-Number: 4469 On 6 Jun 2002 at 17:14, Oliver Elphick wrote: > On Thu, 2002-06-06 at 14:55, Joshua b. Jore wrote:u > > Don't use currval since some other process might alter the > > sequence between the time you call nextval and currval. > > This is wrong. currval() will always return the last serial assigned in > *the*same*session*. It is not affected by other users at all. Folks, here's a short test which might help. Note the BEGIN. $ psql testing testing=# create sequence test; CREATE testing=# select currval('test'); ERROR: test.currval is not yet defined in this session testing=# select setval('test', 1); setval -------- 1 (1 row) testing=# select currval('test'); currval --------- 1 (1 row) testing=# select currval('test'); currval --------- 1 (1 row) testing=# select currval('test'); currval --------- 1 (1 row) testing=# select currval('test'); currval --------- 1 (1 row) testing=# Then, in another window, I did this: $ psql testing # select nextval('test'); nextval --------- 2 (1 row) testing=# select nextval('test'); nextval --------- 3 (1 row) testing=# select nextval('test'); nextval --------- 4 (1 row) testing=# Then back to the other window: testing=# select currval('test'); currval --------- 1 (1 row) testing=# select nextval('test'); nextval --------- 5 (1 row) testing=# cheers FWIW: I always use nextval when looking for a new ID. -- Dan Langille