Re: how to get id of last insert on a serial type? - Mailing list pgsql-general

From Tom Lane
Subject Re: how to get id of last insert on a serial type?
Date
Msg-id 24673.1021762301@sss.pgh.pa.us
Whole thread Raw
In response to how to get id of last insert on a serial type?  ("Robert J. Sanford, Jr." <rsanford@trefs.com>)
Responses Re: how to get id of last insert on a serial type?
Re: how to get id of last insert on a serial type?
List pgsql-general
"Robert J. Sanford, Jr." <rsanford@trefs.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

pgsql-general by date:

Previous
From: "Robert J. Sanford, Jr."
Date:
Subject: how to get id of last insert on a serial type?
Next
From: Doug Fields
Date:
Subject: Re: Force a merge join?