Re: Last ID Problem

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Last ID Problem
Дата
Msg-id 20050201014555.GA52533@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: Last ID Problem  (Mitch Pirtle <mitch.pirtle@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: Last ID Problem
Следующее
От: "Mike G."
Дата:
Сообщение: Re: pgAdminIII and User Grants