Re: using sequences

From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: Erik Price <eprice(at)ptc(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: using sequences
Date: 2003-06-15 14:48:56
Message-ID: 3EEC8758.7050204@wildenhain.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John Smith 2003-06-15 16:27:25 Re: Lyris -> PG 7.1.3
Previous Message Robert C. Paulsen Jr. 2003-06-15 12:22:11 Re: crypt vs password in pg_hba.conf