results via pgAdmin but not via psycopg2 - Mailing list psycopg

From Krystian Samp
Subject results via pgAdmin but not via psycopg2
Date
Msg-id E4D40EAD-6FFA-4CB5-834A-6020146DB1E6@gmail.com
Whole thread Raw
Responses Re: results via pgAdmin but not via psycopg2  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List psycopg
Hello everyone,

I’ve been struggling with an issue for 2 days now and couldn’t find the answer via google search.

here’s a method of my db class:

    def get_old_feeds( self, not_refreshed_for_secs ):
        cursor = self.connection.cursor( cursor_factory = psycopg2.extras.RealDictCursor )
        cursor.execute( "SELECT id, url FROM feeds WHERE refreshed_on is not NULL AND refreshed_on < ( now() - interval
'%sseconds' );", ( not_refreshed_for_secs, ) ) 
        old_feeds = cursor.fetchall()
        cursor.close()
        return old_feeds

there’s a loop that invokes this method every X minutes. All “old_feeds” get their value for “refreshed_on” updated to
thecurrent date when processed using this method: 

    def set_feed_last_refresh( self, feed_id, refresh_datetime ):
        cursor = self.connection.cursor()
        cursor.execute( "UPDATE feeds SET refreshed_on = %s WHERE id = %s;", ( refresh_datetime, feed_id ) )
        self.connection.commit()
        cursor.close()

The problem is that the select query in the first method returns some results only the first time it is run, all
subsequentexecutions give 0 results. The odd thing is that when I issue exactly the same query via pgAdmin I get the
resultsas one would expect. 

I’d highly appreciate your help with this issue,

Thank you,
Krystian

psycopg by date:

Previous
From: Marko Kreen
Date:
Subject: Re: Resdhift's lack of cursors and PQsetSingleRowMode
Next
From: Karsten Hilbert
Date:
Subject: Re: results via pgAdmin but not via psycopg2