Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id D115E9FC131 for ; Thu, 18 Oct 2007 16:09:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 63662-05-3 for ; Thu, 18 Oct 2007 16:09:42 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail63.csoft.net (leary.csoft.net [205.205.214.5]) by postgresql.org (Postfix) with SMTP id 9E31F9FBFEC for ; Thu, 18 Oct 2007 16:09:41 -0300 (ADT) Received: (qmail 19669 invoked by uid 1112); 18 Oct 2007 19:09:39 -0000 Date: Thu, 18 Oct 2007 15:09:39 -0400 (EDT) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Andrei Ilitchev cc: pgsql-jdbc@postgresql.org, Marina Vatkina Subject: Re: Fw: postgresql experts please help In-Reply-To: <00d601c811b7$47c1a6e0$4c349c0a@ca.oracle.com> Message-ID: References: <001101c81189$2f3f52d0$4c349c0a@ca.oracle.com> <00d601c811b7$47c1a6e0$4c349c0a@ca.oracle.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/104 X-Sequence-Number: 17676 On Thu, 18 Oct 2007, Andrei Ilitchev wrote: > In the docs I discovered "select lastval()" which seems to behave exactly > like @@Identity in Sybase returning the latest nextval that was obtained in > the current session by no-matter-which sequence. > That's exactly the functionality I need - much easier to use because no need > to track the name. > > Can you think of any reason why using "select lastval()" would be a bad idea? > If you have an after trigger on the table that you're inserting into and it inserts into another table with a serial column, the lastval call will use the wrong sequence. Now this is also a problem with currval if you have a trigger that inserts into the same table, but that's an unlikely application design. Inserting into another table is something that you'll find with systems that do auditing or sometimes horizontal partitioning of a table. Kris Jurka