Re: Insert and obtain the pk - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: Insert and obtain the pk
Date
Msg-id 20031106184527.GA4495@dcc.uchile.cl
Whole thread Raw
In response to Insert and obtain the pk  ("Eliu Montoya" <eliu@itam.mx>)
List 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!"

pgsql-general by date:

Previous
From: Oleg Bartunov
Date:
Subject: Re: tsearch2 and gist index bloat
Next
From: Peter Eisentraut
Date:
Subject: Re: Install files for version 7.4