psycopg2 weirdness

Philip Semanchuk philip at
Sat Jan 17 19:50:21 CET 2009

On Jan 17, 2009, at 12:48 PM, Neha Gupta wrote:

> Hey,
> I only have little experience with and psycopg2 and am running
> into a weird problem, I'd appreciate any help I can get with debugging
> it.

Hi Neha,
There's a lot of pieces involved here and your subject implies you've  
isolated the problem to psycopg2, but I'm not convinced.

>  I know it is not the date picker that
> causing trouble.

So don't confuse us by mentioning it. =)

> class departures:
> 	def buildDepartureTableHtml(self, date):
>        	web.debug('date', date)
> 		try:
>                      web.debug("About to issue query")
> 			query = "SELECT avg(dep_delay), extract(hour from crs_dep_time) as
> crs_dep_hour, origin from flightdata where date = '01-05-2007' group
> by origin, crs_dep_hour order by origin, crs_dep_hour";
> 			cur.execute(query)
> 			web.debug('query executed!')
> 			rows = cur.fetchall()
> 			web.debug('rows fetched!')
> 			web.debug(rows)
> 		except Exception, e:
> 			print repr(e)
> 			database_conn.rollback()
> 			return "<div id='welcome-text'>Invalid Date</div>"

> You can see above that I even ignored the date passed from the form
> and I have hardcoded '01-05-2007'.

That's a good first step. Simplify even further. What happens if you   
simplify the query? FOr instance:
SELECT 1, 2 as crs_dep_hour, origin
from flightdata
where date = '01-05-2007'

If a simple query like that doesn't work, I suspect you have something  
fundamental wrong with your setup.


More information about the Python-list mailing list