pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <smarlowe@g2switchworks.com>
To: Theodore Petrosky <tedpet5@yahoo.com>
Cc: mail TechEvolution <mail@techevolution.be>
Cc: pgsql-sql@postgresql.org
Subject: Re: getting back autonumber just inserted
Date: Thu, 07 Jul 2005 15:21:49 -0500
Message-ID: <1120767709.8208.188.camel@state.g2switchworks.com> (raw)
In-Reply-To: <20050707201433.94901.qmail@web41013.mail.yahoo.com>
References: <20050707201433.94901.qmail@web41013.mail.yahoo.com>

On Thu, 2005-07-07 at 15:14, Theodore Petrosky wrote:
> you have to use currval inside a transaction...
> 
> begin;
> insert something that increments the counter;
> select currval('sequence_name');
> end;
> 
> using currval inside a transaction guarantees that the
> value is correct for your insert statement and has not
> changed by another insert statement.

Actually, whether you use it inside a transaction or not, as long as
it's in the same session / connection, it is guaranteed to "do the right
thing."

Test it, you'll see.



view thread (30+ messages)  latest in thread

Message-ID: <1120767709.8208.188.camel@state.g2switchworks.com>
Permalink:  ../1120767709.8208.188.camel@state.g2switchworks.com/
Also on:    postgresql.org/message-id/1120767709.8208.188.camel@state.g2switchworks.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: smarlowe@g2switchworks.com, tedpet5@yahoo.com, mail@techevolution.be
  Subject: Re: getting back autonumber just inserted
  In-Reply-To: <1120767709.8208.188.camel@state.g2switchworks.com>

* 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