X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 0359DD1B51C for ; Mon, 8 Sep 2003 22:41:09 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 44527-07 for ; Mon, 8 Sep 2003 19:41:01 -0300 (ADT) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id 6F4CCD1B4EC for ; Mon, 8 Sep 2003 19:40:57 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id h88Mf0o10340; Mon, 8 Sep 2003 18:41:00 -0400 (EDT) From: Bruce Momjian Message-Id: <200309082241.h88Mf0o10340@candle.pha.pa.us> Subject: Re: undefine currval() In-Reply-To: <20030908211254.80421.qmail@web13801.mail.yahoo.com> To: cgg007@yahoo.com Date: Mon, 8 Sep 2003 18:41:00 -0400 (EDT) Cc: pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL106 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/53 X-Sequence-Number: 15031 Chris Gamache wrote: > I'm using sequences and currval() to retrieve the last inserted row in a table. > > > If currval() is undefined, as it is when a connection is made, then I know no > rows were inserted in that table and can take a different action. This is > problematic when using a connection pooling library, as the value of currval() > for any given sequence could possibly be set from a previous "connection". > > One (theoretical) workaround would be to issue some sort of command to the > back-end database to wipe all values of currval() when a "new" connection is > made. I've done some digging in the system tables and source code, and can't > find an obvious solution. Perhaps one you you gurus can suggest a SQL statement > to do such a thing. > > Alternately, if there is a better way to retrieve the last inserted row for any > given table, I'd be very grateful for the tip. It would need to be independent > of the connection history, and undefined if there has not been a row inserted > to the table during a definable interval of time (drop anchor when the > "connection" begins, raise anchor when the "connection" ends), and be > independant of the other connections inserting rows to the same table. I don't know how you could have an application that doesn't know if it has issued a nextval() in the current connection. Unless you can explain that, we have no intention of playing tricks with currval() for connection pooling. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073