Bug? if PyGreSQL, inserttable is used followed by a for loop

Gerhard Häring gerhard at bigfoot.de
Fri May 10 20:04:31 EDT 2002


Anton Setzer wrote in comp.lang.python:
> Hi all,
> 
> I had the following strange behaviour of python,
> which seems to be a bug, either in pygresql or in python itself.
> 
> It happens when accessing postgresql
> through the module pg (PyGreSQL-3.2):

Forget about Darcy's releases. PyGreSQL is part of the PostgreSQL
source tree, that's where you'll find the latest releases, where also
other people are fixing code. In your case, get PyGreSQL out of
src/interfaces/python of your PostgreSQL 7.2.1 source tree.

> After using inserttable, for-loops do no longer work.
> 
> Here is an example session:
> 
> I created a database marksadmin1 with no tables 
> (adding a table kullm (e.g. CREATE TABLE kullm (stud text);) doesn't
> make any difference).
> 
> Then when executing the following python program:
> 
> import pg

Non-DB-API compliant proprietary interface. pgdb is the (sort-of)
DB-API interface in PyGreSQL.

> conn = pg.DB('marksadmin1')
> for j in []:
           ^^

What's the point of this for-loop?

>     print j
> conn.inserttable("kullm",[])
> for j in []:
>     print j
> conn.close()
> 
> I get the following strange errormessage at the line with the 
> second "for j in []"-loop (the first for-loop is okay): 
> 
> IndexError: list index out of range

I doubt it. I see no way for j in [] can ever execute the loop body.

> I am using python 2.2.1, PyGreSQL-3.2, postgresql version 7.2.1.
> 
> The error seems to occur after any execution of inserttable 
> (whether with an empty list or not) followed by arbitrary many
> commands followed by any "for j in mylist:"-loop.
> 
> I have asked D'Arcy J.M. Cain, the current maintainer of  
> PyGreSQL-3.2, who wasn't able to repeat that bug. However
> my installation seems to be the latest non-beta release and
> I haven't encountered any other bugs yet. 
> 

> Does anybody encounter the same problem? Or does anybody know what's
> wrong or what to do about it.

Use pyPgSQL or psycopg. If that sounds harsh, so be it.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))



More information about the Python-list mailing list