Re: [GENERAL] get the previous assigned sequence value - Mailing list pgsql-general

From Ross J. Reedstrom
Subject Re: [GENERAL] get the previous assigned sequence value
Date
Msg-id 19991209103532.B6311@rice.edu
Whole thread Raw
In response to Re: [GENERAL] get the previous assigned sequence value  ("Dev Elop" <dev@archonet.com>)
List pgsql-general
Gah, this is getting a bit annoying, correcting this bit of
mis-information.

currval() is kept as part of the session context, as is completely
multi-user safe. That's why the person you quoted said 'in the same
session'.

Where is everyone coming up with the wrong idea on this? Is there a
major commercial DB with sequence objects that gets this wrong?

Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005



On Thu, Dec 09, 1999 at 10:36:40AM -0000, Dev Elop wrote:
> > >
> > > After an INSERT, I want to retrieve the value of the sequence I use for
> > > unique_ids
> > >
> ...
> >
> > Alternatively, use the currval(mytable_id_seq) function within the same
> > session immediately after the insert.
> >
> With this second method, you'd probably need to beware race conditions. If
> another process inserts a record into mytable after you do but before you
> call currval(), then you'll get the wrong value.
>
> Not an issue if you've only got one process accessing the table - probably
> is one if you have two or more.
>
> -
>   Richard Huxton
>
>
> ************
>

pgsql-general by date:

Previous
From: "Ross J. Reedstrom"
Date:
Subject: Re: [GENERAL] How to stop implicit rollback on certain errors?
Next
From: Bruce Momjian
Date:
Subject: Re: [GENERAL] Problems with pg_dump