Thread: Obtaining the primary key of the record just inserted

Obtaining the primary key of the record just inserted

From
"Oliveiros Cristina"
Date:
Hello, All,
 
I have the need to know the primary key assigned to a record I've just INSERTed .
 
Is there an easy way to solve this ?
 
Similar to SQLServer's  SELECT scope_identity() ; ?
 
Any help deeply appreciated
 
Best,
Oliveiros

Re: Obtaining the primary key of the record just inserted

From
Sean Davis
Date:
Oliveiros Cristina wrote:
> Hello, All,
>
> I have the need to know the primary key assigned to a record I've just
> INSERTed .
>
> Is there an easy way to solve this ?
>
> Similar to SQLServer's  SELECT scope_identity() ; ?
>
> Any help deeply appreciated
Is the primary key a SERIAL column?

Sean


Re: Obtaining the primary key of the record just inserted

From
Hans-Peter Oeri
Date:
Hi!

Oliveiros Cristina wrote:
I have the need to know the primary key assigned to a record I've just INSERTed .
Is there an easy way to solve this ?
I prefer:
INSERT INTO [...] RETURNING id;

HPO