Re: Obtaining the primary key of the record just inserted

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "Oliveiros Cristina" <oliveiros(dot)cristina(at)marktest(dot)pt>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Obtaining the primary key of the record just inserted
Date: 2007-11-08 18:03:00
Message-ID: dcc563d10711081003o515df294mdbf2b3bde2fe6b85@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Nov 8, 2007 11:56 AM, Oliveiros Cristina
<oliveiros(dot)cristina(at)marktest(dot)pt> 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() ; ?

In 8.2 and up:

insert into table a (info) values ('abc') returning id;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Oliveiros Cristina 2007-11-08 19:10:41 Re: Obtaining the primary key of the record just inserted
Previous Message Oliveiros Cristina 2007-11-08 17:56:14 Obtaining the primary key of the record just inserted