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

Re: Sequences, defaults and getting a new key

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Willden <jeff(at)pavanell(dot)com>
Cc: PostgreSQL List - Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Sequences, defaults and getting a new key
Date: 2008-02-22 05:16:44
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Jeff Willden <jeff(at)pavanell(dot)com> writes:
> When the primary key of a table defaults to the nextval() of a  
> sequence, if you insert a new record into the table and accept the  
> default, how do you then select the value that was just used as the  
> new primary key and guarantee that you don't accidentally get the  
> value that another user just generated at about the same instant?

currval() or INSERT RETURNING would do it.  Check the archives for
a few thousand prior discussions ...

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Alex du PlessisDate: 2008-02-22 10:24:32
Subject: Trigger question
Previous:From: Jeff WilldenDate: 2008-02-22 04:28:13
Subject: Sequences, defaults and getting a new key

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