Julio E. Martinez wrote:

> Hello, I've been using pygresql and it's been working great. Recently I 
> hit a snag. As part of my project I have to find out what the server's 
> time is every once in a while. I use "SELECT now()" for this. The 
> problem is that unless another completely different connection comes in 
> and changes the database the result (database time) will not change. The 
> same happens for SELECT CURRENT_TIMESTAMP as well. If i do this 
> connected to the same database with psql it works properly (gives the 
> actual time). I've also tried getting a new cursor every time i fetch 
> the date. If does not change anything. Here are the (what i think)  
> relevant versions of libraries/server I'm using.
> 
> The server: PostgreSQL 8.1.11 on x86_64-redhat-linux-gnu, compiled by 
> GCC gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
> The client libraries: 8.2.14 (on gentoo)
> The pygresql module: 4.0 (on gentoo)
> 
> If this where a bug I would be willing do cooperate in fixing it. Just 
> don't know where to start, or if it's even a bug at all. Could not find 
> anything in google so if anybody has some insight into this any advice 
> is welcome.
> 
> Thanks,
> Julio

hi julio,

if you were using postgresql-8.4.x you could select clock_timestamp()
but 8.1 doesn't seem to have that function according to
its doco (http://www.postgresql.org/docs/8.1/static/functions-datetime.html).

what 8.1 does have is select timeofday() which returns the
actual current time (not the start of the transaction)
but it returns it as text not as a timestamp. you can
probably cast it to a timestamp, though.

however, select now() returns the time at the start of the
transaction, not the time at the start of the connection
as you are seeing. that probably means that you are using
an old version of pygresql that keeps a transaction open
all the time. upgrading to pygresql-4 will solve your
problem unless you really have long running transactions
and need to know the time at various points inside it. 
if that's the case, then you need to select timeofday().

if you can't upgrade postgresql or pygresql then you
need to commit the current transaction (which will start
a new transaction in old versions of pygresql) and then
select now().

cheers,
raf

_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to