Re: getting currval from a sequence

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: getting currval from a sequence
Дата
Msg-id 200202111850.g1BIo5C29098@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: getting currval from a sequence  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-general
Bruno Wolff III wrote:
> On Mon, Feb 11, 2002 at 11:42:31AM +0100,
>   tony <tony@animaproductions.com> wrote:
> >
> > How does one get the last record from a series of records? I just need
> > the id field which is a sequence field
>
> select max(id) from whatever;
> (This assumes the sequence hasn't rolled over.)

You can do a select on the sequence table that lays behind the sequence.
usually ending in _seq.  You can't use currval() because that is a
per-backend value that saves your previous nextval call.  Make sure you
lock the sequence table during the retrieve if you want an accurate
number and don't unlock it until you are done with the value.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

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

Предыдущее
От: Darren Ferguson
Дата:
Сообщение: Re: getting currval from a sequence - BUG ?
Следующее
От: Doug McNaught
Дата:
Сообщение: Re: compiling on sco