Re: Last ID Problem - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: Last ID Problem
Date
Msg-id 20050209173828.GA6212@winnie.fuhr.org
Whole thread Raw
In response to Re: Last ID Problem  (<operationsengineer1@yahoo.com>)
List pgsql-novice
On Wed, Feb 09, 2005 at 08:53:18AM -0800, operationsengineer1@yahoo.com wrote:

> so, i should use nextval() if i use mitch's
> methodology of calling the id first then performing
> the insert.

Right.  You can call nextval() first and then explicitly insert the
value you obtained, or you can do the insert first and let the
serial column's default expression call nextval() automatically,
and you can then find out the value it used with a subsequent call
to currval().

> giving that nextval increments on a refresh, is there
> anything i need to worry about?

nextval() increments the sequence each time it's called.  If you're
using the sequence values as keys, then that's what you need.
Presumably you'd only call nextval() when you're going to insert a
new record, so what's the concern?

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-novice by date:

Previous
From: "Oisin Glynn"
Date:
Subject: Returning a long string (varchar from a function)
Next
From: Michael Fuhr
Date:
Subject: Re: Returning a long string (varchar from a function)