Re: how to get id of last insert on a serial type?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Robert J(dot) Sanford, Jr(dot)" <rsanford(at)trefs(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to get id of last insert on a serial type?
Date: 2002-05-18 22:51:41
Message-ID: 24673.1021762301@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Robert J. Sanford, Jr." <rsanford(at)trefs(dot)com> writes:
> one bit that I'm currently having the largest issue with is the
> @@IDENTITY property. For those not familiar with SQL Server,
> performing "SELECT @@IDENTITY" allows a user to retrieve the primary
> key of the last row inserted into a table (assuming the table is
> using an identity column as the primary key)

Use a serial column as the primary key, and then @@IDENTITY can be
implemented as currval() on the associated sequence. This is more
flexible than what you describe for SQL Server, because the currval
can be retrieved at any later time in the same session --- as long
as you don't do another insert into the same table, it's still good.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert J. Sanford, Jr. 2002-05-18 22:56:26 how to get id of last insert on a serial type?
Previous Message Doug Fields 2002-05-18 22:50:00 Re: Force a merge join?