Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id C7192476488 for ; Mon, 6 May 2002 15:18:31 -0400 (EDT) Received: from fw.mccons.net (adsl-65-64-105-41.dsl.kscymo.swbell.net [65.64.105.41]) by postgresql.org (Postfix) with ESMTP id 55C05475C4B for ; Mon, 6 May 2002 14:49:17 -0400 (EDT) Received: (from root@localhost) by fw.mccons.net (8.11.3/8.11.4) id g46InHx15737 for pgsql-admin@postgresql.org; Mon, 6 May 2002 13:49:17 -0500 (CDT) (envelope-from bmccane@mccons.net) Received: from localhost (localhost [127.0.0.1]) by fw.mccons.net (8.11.3/8.11.4av) with ESMTP id g46In7c15725 for ; Mon, 6 May 2002 13:49:07 -0500 (CDT) (envelope-from bmccane@mccons.net) Date: Mon, 6 May 2002 13:49:07 -0500 (CDT) From: Brian McCane To: Subject: Re: SERIAL Field Message-ID: <20020506134836.B12755-100000@fw.mccons.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS perl-11 X-Razor-Spam-ID: 42f6501832b1d4b6b3f405c8dbe7494f941b3471 X-Archive-Number: 200205/37 X-Sequence-Number: 4212 My personal experience is that you MUST operate like: SELECT nextval... INSERT ... I have several web sites that have many simultaneous updates occurring, based on user interaction with the website and its underlying data structures. I used to INSERT, then SELECT currval, and depending on timing, I might get a different sequence number than the one I actually used. Apparently I had the following occurring: INSERT ... INSERT ... SELECT currval... SELECT currval... In this situation, both of the SELECTs return the same sequence number. So basically, user1 would update user2's "myarea" data. This problem became much more critical when I went to multiple Apache servers on the front end and had a higher likelihood of concurrency. However, even on a single server, you can't guarantee where the task switch will occur and mess you up. - brian On Mon, 6 May 2002, Joel Burton wrote: > > > -----Original Message----- > > From: Dan Langille [mailto:dan@langille.org] > > Sent: Monday, May 06, 2002 12:41 PM > > To: Joel Burton > > Cc: pgsql-admin@postgresql.org > > Subject: Re: [ADMIN] SERIAL Field > > > > > In any event, inserting then using currval() is the standard practice > > > around here, and it works great. Nothing fishy at all here, > > nothing to see, > > > move on. > > > > Why is that "less risk"? > > It's not; nextval() is just fine. I was half asleep and thinking, I think, > of another database when I wrote that. > > "You say nextval() + write, I say write + currval()..." > > J. > > Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton > Knowledge Management & Technology Consultant > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org > Wm. Brian McCane | Life is full of doors that won't open Search http://recall.maxbaud.net/ | when you knock, equally spaced amid those Usenet http://freenews.maxbaud.net/ | that open when you don't want them to. Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"