Re: Select nextval problem - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Select nextval problem
Date
Msg-id 20021127234152.GA29884@svana.org
Whole thread Raw
In response to Re: Select nextval problem  (SZUCS Gábor <surrano@mailbox.hu>)
List 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.

Attachment

pgsql-general by date:

Previous
From: Jim Worke
Date:
Subject: Bad timestamp external representation
Next
From: "Nigel J. Andrews"
Date:
Subject: Why does everyone think MySQL is easier?