Re: Last ID Problem - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: Last ID Problem
Date
Msg-id 20050201014555.GA52533@winnie.fuhr.org
Whole thread Raw
In response to Re: Last ID Problem  (Mitch Pirtle <mitch.pirtle@gmail.com>)
List pgsql-novice
On Mon, Jan 31, 2005 at 07:58:42PM -0500, Mitch Pirtle wrote:

> That is because you are doing it out of order.  First, you get the
> sequence id, and THEN you use that number for your INSERT statement:

Common practice when using a sequence in PostgreSQL is to do the
INSERT first, then call currval() to find out what value you got.
If you want to obtain the sequence value first then use nextval(),
not currval() as your code showed.  Calling currval() before any
calls to nextval() should fail with an error like the following:

currval of sequence "customer_cust_id_seq" is not yet defined in this session

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-novice by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Last ID Problem
Next
From: "Mike G."
Date:
Subject: Re: pgAdminIII and User Grants