Re: Insert and obtain the pk

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Eliu Montoya <eliu(at)itam(dot)mx>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Insert and obtain the pk
Date: 2003-11-06 18:45:27
Message-ID: 20031106184527.GA4495@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Nov 06, 2003 at 12:26:48PM -0600, Eliu Montoya wrote:

> Does anyone know an easy way to insert a record (without a value for the
> primary key because it is a sequence) and at the same time obtain the value
> of primary key that was assign to this new record.

Given that you are already using a sequence, you can obtain the last
value given to you by means of currval(). No, this doesn't have any
concurrency problems with multiple backends inserting at the same time;
that's exactly the problem it solves.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"In Europe they call me Niklaus Wirth; in the US they call me Nickel's worth.
That's because in Europe they call me by name, and in the US by value!"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2003-11-06 18:50:59 Re: Install files for version 7.4
Previous Message Oleg Bartunov 2003-11-06 18:32:18 Re: tsearch2 and gist index bloat