Re: Last ID Problem

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: operationsengineer1(at)yahoo(dot)com
Cc: Mitch Pirtle <mitch(dot)pirtle(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Last ID Problem
Date: 2005-02-09 17:38:28
Message-ID: 20050209173828.GA6212@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice

On Wed, Feb 09, 2005 at 08:53:18AM -0800, operationsengineer1(at)yahoo(dot)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/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Gavin M. Roy 2005-02-09 19:41:19 Re: PHP/PDO Database Abstraction Layer
Previous Message operationsengineer1 2005-02-09 16:53:18 Re: Last ID Problem

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Fuhr 2005-02-09 17:51:35 Re: Returning a long string (varchar from a function)
Previous Message Oisin Glynn 2005-02-09 17:30:51 Returning a long string (varchar from a function)