pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Gamache <cgg007@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: undefine currval()
Date: Mon, 8 Sep 2003 14:12:54 -0700 (PDT)
Message-ID: <20030908211254.80421.qmail@web13801.mail.yahoo.com> (raw)
In-Reply-To: <15403.1063035632@sss.pgh.pa.us>

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.

Any idaeas?

CG

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com



view thread (7+ messages)  latest in thread

Message-ID: <20030908211254.80421.qmail@web13801.mail.yahoo.com>
Permalink:  ../20030908211254.80421.qmail@web13801.mail.yahoo.com/
Also on:    postgresql.org/message-id/20030908211254.80421.qmail@web13801.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: cgg007@yahoo.com
  Subject: Re: undefine currval()
  In-Reply-To: <20030908211254.80421.qmail@web13801.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox