Re: Last ID Problem - Mailing list pgsql-novice

From Bruno Wolff III
Subject Re: Last ID Problem
Date
Msg-id 20050504165626.GB30968@wolff.to
Whole thread Raw
In response to Re: Last ID Problem  (<operationsengineer1@yahoo.com>)
List pgsql-novice
On Wed, May 04, 2005 at 09:21:52 -0700,
  operationsengineer1@yahoo.com wrote:
> > Why not first get the current value from the
> > sequence, use it for your
> > INSERT statement, and then have it handy for the
> > rest of the script?
>
> i hate to revisit this old topic, however, i just want
> to make sure i'm avoiding future problems.
>
> if i pull nextval then insert it into the id column
> where i pulled it from, will the counter ever get "off
> track" since i'm doing manual inserts?

What do you mean by off track? nextval will return a unique value each
time it is called. If you want to refer to the last value returned by
nextval in the same session, you should use currval.

> can nextval ever become a value that's unexpected?  in
> practice, this method is working very well, but i'm
> paranoid.  ;-)

When you reach the maximum value for the sequence then you will get an
error. The default maximum value for 8.0 appears to be 9223372036854775807.
If you store the value in a 4 byte integer, then you will have problems
sooner.

pgsql-novice by date:

Previous
From:
Date:
Subject: Re: Last ID Problem
Next
From: "sZEJTAN"
Date:
Subject: date update check