From: Brian McCane <bmccane@mccons.net>
To: pgsql-admin@postgresql.org
Subject: Re: SERIAL Field
Date: Mon, 6 May 2002 13:49:07 -0500 (CDT)
Message-ID: <20020506134836.B12755-100000@fw.mccons.net> (raw)
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"
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-admin@postgresql.org
Cc: bmccane@mccons.net
Subject: Re: SERIAL Field
In-Reply-To: <20020506134836.B12755-100000@fw.mccons.net>
References: <20020506134836.B12755-100000@fw.mccons.net>
* 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