Replacing IDENTITY with lastval() - Mailing list pgsql-odbc

From Dmitry Samokhin
Subject Replacing IDENTITY with lastval()
Date
Msg-id E1HjwBJ-000Hnc-00.sdld-mail-ru@f105.mail.ru
Whole thread Raw
Responses Re: Replacing IDENTITY with lastval()
Re: Replacing IDENTITY with lastval()
List pgsql-odbc
Accordind to the release notes, "Use lastval() function to replace IDENTITY on 8.1 or later servers" was introduced in
release8.2.0205. This may cause incorrect results: "<...> assumes that your database does not expect any triggers to
firewhen the INSERT is executed. If a trigger does fire and if that trigger adds another row to a table, the @@IDENTITY
globalvariable would be set to point to that new Identity value—not the one your INSERT generated. <...> work for
simplesituations, but not when your database gets more sophisticated". 
See "Managing an @@IDENTITY Crisis" on MSDN (http://msdn2.microsoft.com/en-us/library/ms971502.aspx) for more details.

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

Please consider to revert the code.

Regards,
Dmitry.

pgsql-odbc by date:

Previous
From: "Hiroshi Saito"
Date:
Subject: Re: Driver manager detection in 08.02.0400 is broken
Next
From: Peter Eisentraut
Date:
Subject: Re: Driver manager detection in 08.02.0400 is broken