[PyGreSQL] Cached statements

Mark Lee mark at geneity.co.uk
Tue May 2 10:20:23 EDT 2006


Hello. Firstly, I'm new to Python so please bare that in mind when
berating me for my stupidity.

I'm having trouble with the following piece of code. This is just a
stipped down example but persuaded me that the problem I'm getting lay
within the pygres module. When this is run, it would appear the "now()"
is evaluated at statement preparation or initial execution time. For
each successive call to execute it would appear that now() is not
re-evaluated and remains the same as the first time through the loop.

The only way I can get this piece of sql to work is by closing and
reestablishing the database connection each time or to pass the datetime
through from python in place of "now()" which is inadequate as the host
running python and the host with the database may be out of sync time
wise.

I've used postgres via other languages and never seen this "feature".
Bug, feature or programming error?

thanks,

Mark


import pgdb
import time

conn = pgdb.connect(database='test')
curs = conn.cursor()

while True:
	curs.execute("select last_update from test where test_id = 1 and last_update + interval '20 seconds' < now()")
	print curs.fetchone()
	time.sleep(5)
						



More information about the PyGreSQL mailing list