Re: Select nextval problem

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Select nextval problem
Дата
Msg-id 20021127234152.GA29884@svana.org
обсуждение исходный текст
Ответ на Re: Select nextval problem  (SZUCS Gábor <surrano@mailbox.hu>)
Список pgsql-general
On Wed, Nov 27, 2002 at 06:15:04PM +0100, SZUCS Gábor wrote:
> 2. There is something called currval(...) that doesn't increase the counter,
> just returns its current value. In our lucky case, you need something that
> can be queried with this function, so I'd say either of the following will
> do:
>
>   SELECT * FROM product WHERE prodid = currval('prodid_seq');
>   SELECT * FROM product ORDER BY prodid DESC LIMIT 1;
>
> Both of these, however, assume that you haven't inserted any rows after the
> one in question.

Wrong. The second one does. The first guarenteed to return what the earlier
nextval() returned. It is therefore the recommended method. Lookup the
documentation for more details.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Support bacteria! They're the only culture some people have.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Jim Worke
Дата:
Сообщение: Bad timestamp external representation
Следующее
От: "Nigel J. Andrews"
Дата:
Сообщение: Why does everyone think MySQL is easier?