Re: SELECT @@IDENTITY

From: Steve Lane <slane(at)moyergroup(dot)com>
To: "Robert J(dot) Sanford, Jr(dot)" <rsanford(at)trefs(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: SELECT @@IDENTITY
Date: 2003-06-23 18:11:27
Message-ID: BB1CACFF.3275D%slane@moyergroup.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/23/03 12:58 PM, "Robert J. Sanford, Jr." <rsanford(at)trefs(dot)com> wrote:

> Okay, I did a quick search through both the general and SQL lists(1,2)
> trying to determine if there is a PostgreSQL construct equivalent to
> Microsoft SQL Server's "SELECT @@IDENTITY". After performing an insert the
> database caches the last sequence number for each connection and the select
> retrieves that value. Thus if connection A and connection B each inserted
> into the same table they would each know what the value of the sequence was
> immediately after their insert.
>
> Is there any direct support for this? I know that I can manually code to
> select the nextval of a sequence but the syntactic sugar of SELECT
> @@IDENTITY is really nice.
>
> Many thanks!

Hi Robert:

You'll want to consult the postgres docs about sequences. The function
you're looking for is called currval(), and selects just what you want --
the most recent value delivered for a sequence over a given connection.
(I've always been curious about how well this behaves, or not, with
connection pooling).

-- sgl

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2003-06-23 18:32:38 Re: MySQL/PG search times
Previous Message nolan 2003-06-23 18:11:19 MySQL/PG search times