From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Mitch Pirtle <mitch(dot)pirtle(at)gmail(dot)com> |
Cc: | "operationsengineer1(at)yahoo(dot)com" <operationsengineer1(at)yahoo(dot)com>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Last ID Problem |
Date: | 2005-02-01 01:45:55 |
Message-ID: | 20050201014555.GA52533@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers 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/
From | Date | Subject | |
---|---|---|---|
Next Message | Mitch Pirtle | 2005-02-01 01:55:22 | Re: Last ID Problem |
Previous Message | Michael Fuhr | 2005-02-01 01:38:55 | Re: Last ID Problem |
From | Date | Subject | |
---|---|---|---|
Next Message | Mike G. | 2005-02-01 01:53:55 | Re: pgAdminIII and User Grants |
Previous Message | Michael Fuhr | 2005-02-01 01:38:55 | Re: Last ID Problem |