Re: [GENERAL] get the previous assigned sequence value

From: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
To: Dev Elop <dev(at)archonet(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] get the previous assigned sequence value
Date: 1999-12-09 16:35:32
Message-ID: 19991209103532.B6311@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)rice(dot)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
>
>
> ************
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message kaiq 1999-12-09 16:44:32 Re: [GENERAL] Error: Using Large Objects by perl5-Interface
Previous Message Ross J. Reedstrom 1999-12-09 16:24:18 Re: [GENERAL] How to stop implicit rollback on certain errors?