|
Bug report with dictcursor: msg#00005python.db.psycopg.devel
Problem : Using the cursor as an iterable seems to yield DictRow's which behave like non-Dict rows (ie. no string keys). Bug ? Example : cursor = db.cursor( cursor_factory = psycopg2.extras.DictCursor ) # This code works : cursor.execute( "SELECT id FROM users LIMIT 2" ) for row in cursor.fetchall(): print "row :", row, type(row) for key in 0,'id': try: print key, row[key] except: traceback.print_exc() # Results : row : [1] <class 'psycopg2.extras.DictRow'> 0 1 id 1 row : [2] <class 'psycopg2.extras.DictRow'> 0 2 id 2 # Here we have removed .fetchall(), because the cursor is an iterable. cursor.execute( "SELECT id FROM users LIMIT 2" ) for row in cursor: print "row :", row, type(row) for key in 0,'id': try: print key, row[key] except: traceback.print_exc() # Results : 0 1 Traceback (most recent call last): File "test.py", line 25, in ? print key, row[key] File "/usr/lib64/python2.4/site-packages/psycopg2/extras.py", line 75, in __getitem__ x = self._index[x] KeyError: 'id' id row : [2] <class 'psycopg2.extras.DictRow'> 0 2 Traceback (most recent call last): File "test.py", line 25, in ? print key, row[key] File "/usr/lib64/python2.4/site-packages/psycopg2/extras.py", line 75, in __getitem__ x = self._index[x] KeyError: 'id' id ####################### |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: #99: Patch for cursor.execute and cursor.executemany to return cursor object: 00005, PFC |
|---|---|
| Next by Date: | Re: Bug report with dictcursor: 00005, Federico Di Gregorio |
| Previous by Thread: | Re: #99: Patch for cursor.execute and cursor.executemany to return cursor objecti: 00005, Markus Bertheau |
| Next by Thread: | Re: Bug report with dictcursor: 00005, Federico Di Gregorio |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |