Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 0C3549FB731 for ; Sat, 5 May 2007 13:47:33 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 89425-03 for ; Sat, 5 May 2007 13:47:29 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (Postfix) with SMTP id 9DDCF9FB841 for ; Sat, 5 May 2007 13:47:29 -0300 (ADT) Received: (qmail invoked by alias); 05 May 2007 16:47:28 -0000 Received: from i3ED6DEBD.versanet.de (EHLO [192.168.0.112]) [62.214.222.189] by mail.gmx.net (mp030) with SMTP; 05 May 2007 18:47:28 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX1+T3Zdcf7eTVabkXfNmu/TyR+IqQt4nahdROFKVxp SbfJ4DMw8wsLip Message-ID: <463CB520.90208@gmx.net> Date: Sat, 05 May 2007 18:47:28 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.8.1.2) Gecko/20070222 SeaMonkey/1.1.1 MIME-Version: 1.0 To: pgsql-odbc@postgresql.org Subject: Re: Replacing IDENTITY with lastval() References: In-Reply-To: Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 8bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/33 X-Sequence-Number: 8946 So - generally speaking - it is not advised to use lastval() at all? At least not, if one is not 110% sure what happens in the application now and on later modifications of the client application. Thats a pitty, as I have only known lastval() for about 15 minutes when I looked in the documentation for the sequence stuff. On the other hand I ran today in troubles with sequences when I was doing a bit coding on a migration from MS-Access DAO + JET to DAO, ODBC + PG. With pure Access + DAO one can fetch the newly assigned AUTOVALUE by simply reading it out of the newly created record right after AddNew and before Update. With ODBC + PG. as backend the SERIAL is undefined between AddNew and Update. And the recordset points not to the new record after Update but to the first record in the recordset. I had to use PG's CurrVal respectivly LastVal which would be easier without having to know the name of the sequence. I'm happy that I read your post before using LastVal all over the place. :) Dmitry Samokhin schrieb: > 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 (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 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. > > Regards, > Dmitry. > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster > >