From: | Brian McCane <bmccane(at)mccons(dot)net> |
---|---|
To: | <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: SERIAL Field |
Date: | 2002-05-06 18:49:07 |
Message-ID: | 20020506134836.B12755-100000@fw.mccons.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
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(at)langille(dot)org]
> > Sent: Monday, May 06, 2002 12:41 PM
> > To: Joel Burton
> > Cc: pgsql-admin(at)postgresql(dot)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(at)joelburton(dot)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"
From | Date | Subject | |
---|---|---|---|
Next Message | Joel Stevenson | 2002-05-06 19:29:17 | Re: SERIAL Field |
Previous Message | Bolek Bakowski | 2002-05-06 18:35:45 | Connection to multiple databases |