Skip site navigation (1) Skip section navigation (2)

Replacing IDENTITY with lastval()

From: Dmitry Samokhin <sdld(at)mail(dot)ru>
To: pgsql-odbc(at)postgresql(dot)org
Subject: Replacing IDENTITY with lastval()
Date: 2007-05-04 11:42:37
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-odbc
Accordind to the release notes, "Use lastval() function to replace IDENTITY on 8.1 or later servers" was introduced in release 8.2.0205. This may cause incorrect results: "<...> assumes that your database does not expect any triggers to fire when the INSERT is executed. If a trigger does fire and if that trigger adds another row to a table, the @@IDENTITY global variable would be set to point to that new Identity value—not the one your INSERT generated. <...> work for simple situations, but not when your database gets more sophisticated".
See "Managing an @@IDENTITY Crisis" on MSDN ( for more details.

The PostgreSQL documentation states that the lastval() function returns the value most recently returned by nextval in the current session. It works the same way as the @@IDENTITY variable in MSSQL. The currval(...) function returns a value of the explicitly specified sequence, this is exactly what we need.

Please consider to revert the code.



pgsql-odbc by date

Next:From: Peter EisentrautDate: 2007-05-04 11:54:19
Subject: Re: Driver manager detection in 08.02.0400 is broken
Previous:From: Hiroshi SaitoDate: 2007-05-04 11:37:08
Subject: Re: Driver manager detection in 08.02.0400 is broken

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group