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