Re: collision in serial numbers after INSERT? - Mailing list pgsql-general

From Bill Moran
Subject Re: collision in serial numbers after INSERT?
Date
Msg-id 20070603180801.b4f608fe.wmoran@potentialtech.com
Whole thread Raw
In response to Re: collision in serial numbers after INSERT?  (Steve Lefevre <lefevre.10@osu.edu>)
List pgsql-general
Steve Lefevre <lefevre.10@osu.edu> wrote:
>
> Bill Moran wrote:
> > Don't do that. Please let us know what site recommended that so I can
> > send an email to the author correcting them.
> >
> Hello Bill -
>
> The 'offending' site and article is at
> http://www.sitepoint.com/article/site-mysql-postgresql-2/3

My goodness, that article is ancient.  2001.  I have a hard time
believing he's going to update it if it's been wrong that long.

> > Instead, do SELECT currval('<seqname>'), which is guaranteed to be isolated
> > from other sessions.
> >
> I've also gotten other advice to SELECT next_val ( whatever the exact
> wording is) will reserve that serial number for you. Is that true?

Yes, please see the documentation.  Both currval() and next_val() are
transaction safe (thus guaranteed not to cause overlapped serials) but
they do slightly different things.

--
Bill Moran
http://www.potentialtech.com

pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Multiple customers sharing one database?
Next
From: Jeff Davis
Date:
Subject: Re: multimaster