pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Theodore Petrosky <tedpet5@yahoo.com>
To: mail TechEvolution <mail@techevolution.be>
Cc: pgsql-sql@postgresql.org
Subject: Re: getting back autonumber just inserted
Date: Thu, 7 Jul 2005 13:14:33 -0700 (PDT)
Message-ID: <20050707201433.94901.qmail@web41013.mail.yahoo.com> (raw)
In-Reply-To: <42CD6B58.6060508@techevolution.be>


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.

Ted


--- mail TechEvolution <mail@techevolution.be> wrote:

> hello
> 
> i ame a newbie to PostGreSQL, I ame using PostGreSQL
> 8.0 
> (windowsinstaller) on a xp prof platform
> 
> i would like to get back the autonumber from the
> last record inserted, 
> for other SQL db (m$ sql db ...) i could use:
> SELECT @@ IDENTITY
> 
> can someone help me by informing me what the SQL
> syntax is to be used 
> with PostGreSQL db and get the same result, the last
> autonumber inserted?
> 
> greeTz
> 
> wes
> 
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 



		
____________________________________________________
Sell on Yahoo! Auctions – no fees. Bid on great items.  
http://auctions.yahoo.com/



view thread (30+ messages)  latest in thread

Message-ID: <20050707201433.94901.qmail@web41013.mail.yahoo.com>
Permalink:  ../20050707201433.94901.qmail@web41013.mail.yahoo.com/
Also on:    postgresql.org/message-id/20050707201433.94901.qmail@web41013.mail.yahoo.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: tedpet5@yahoo.com, mail@techevolution.be
  Subject: Re: getting back autonumber just inserted
  In-Reply-To: <20050707201433.94901.qmail@web41013.mail.yahoo.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