Re: using sequences - Mailing list pgsql-general

From Tino Wildenhain
Subject Re: using sequences
Date
Msg-id 3EEC8758.7050204@wildenhain.de
Whole thread Raw
In response to using sequences  (Erik Price <eprice@ptc.com>)
List pgsql-general
Hi Erik,

Erik Price wrote:
> I have read the manual about sequences and I thought I understood both
> their purpose and how to use them.  When I perform inserts, the sequence
> is updated appropriately.  However, I can't seem to directly access the
> sequence myself.  I always seem to get this message:
>
> be_db=# select currval('news_news_id_seq');
> ERROR:  news_news_id_seq.currval is not yet defined in this session
>
> Can someone explain what is going on?

This is a FAQ. Although it is mentioned clearly in the documentation,
it is often overread:

currval() is only valid after nextval() in your transaction.
This is to get the id for your last insert or whatever and
_not_ the id of some other insert concurrently running.

Does this help?

Regards
Tino Wildenhain


pgsql-general by date:

Previous
From: "Robert C. Paulsen Jr."
Date:
Subject: Re: crypt vs password in pg_hba.conf
Next
From: John Smith
Date:
Subject: Re: Lyris -> PG 7.1.3