Skip site navigation (1) Skip section navigation (2)

Re: nextval() clarification

From: Ron St-Pierre <rstpierre(at)syscor(dot)com>
To: Greg Donald <destiney(at)gmail(dot)com>,pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: nextval() clarification
Date: 2004-09-13 22:01:10
Message-ID: 414618A6.7040806@syscor.com (view raw or flat)
Thread:
Lists: pgsql-novice
Greg Donald wrote:

>On Mon, 13 Sep 2004 21:54:11 +0200, Ennio-Sr <nasr(dot)laili(at)tin(dot)it> wrote:
>  
>
>>I think you should put <nextval(....)> directly into the INSERT
>>instruction, so that it advances only once per added record.
>>Have a look at Documentation PostgreSQL 7.4, Ch 9.11, table 9.34.
>>HTH
>>    
>>
>
>I would but then I don't know how to ensure I return that exact same
>id from the insert, like mysql_insert_id() does.  That's the whole
>reason why I aquire the id first, so I know what it is after the
>insert.  SELECT max(id) would be off under load I think.
>
>I just didn't understand why it appeared to be +2 and not +1 as a
>novice might expect.  But now I get it.  Thanks to all.
>
>  
>
After your insert statement, you can call CURRVAL to find out what the 
value was that you
inserted into the serial column.

eg SELECT currval('companies_company_id_seq'::text)

Ron


In response to

pgsql-novice by date

Next:From: Michael FuhrDate: 2004-09-13 22:02:26
Subject: Re: nextval() clarification
Previous:From: ghaverlaDate: 2004-09-13 21:55:56
Subject: Re: Subnovice question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group