This project is archived and is in readonly mode.
cursor rownumber fails
-
Daniele Varrazzo
Hi Mariano,
Can't reproduce what you say: can you provide an example? I've tried with regular cursors as well with DictCursor and NamedTupleCursor:
In [1]: import psycopg2 In [2]: cnn = psycopg2.connect('') In [3]: cur = cnn.cursor() In [4]: cur.execute('select * from generate_series(1,10)') In [5]: cur.rownumber, cur.rowcount Out[5]: (0, 10) In [7]: cur.fetchone() Out[7]: (1,) In [8]: cur.rownumber, cur.rowcount Out[8]: (1, 10) In [9]: cur.fetchmany(3) Out[9]: [(2,), (3,), (4,)] In [10]: cur.rownumber, cur.rowcount Out[10]: (4, 10) In [11]: import psycopg2.extras In [12]: cur = cnn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor) In [13]: cur.rownumber, cur.rowcount Out[13]: (0, -1) In [14]: cur.execute('select * from generate_series(1,10)') In [15]: cur.rownumber, cur.rowcount Out[15]: (0, 10) In [16]: cur.fetchone() Out[16]: Record(generate_series=1) In [17]: cur.rownumber, cur.rowcount Out[17]: (1, 10) In [18]: cur.fetchmany(3) Out[18]: [Record(generate_series=2), Record(generate_series=3), Record(generate_series=4)] In [19]: cur.rownumber, cur.rowcount Out[19]: (4, 10) In [20]: cur = cnn.cursor(cursor_factory=psycopg2.extras.DictCursor) In [21]: cur.execute('select * from generate_series(1,10)') In [22]: cur.rownumber, cur.rowcount Out[22]: (0, 10) In [23]: cur.fetchone() Out[23]: [1] In [24]: cur.rownumber, cur.rowcount Out[24]: (1, 10) In [25]: cur.fetchmany(3) Out[25]: [[2], [3], [4]] In [26]: cur.rownumber, cur.rowcount Out[26]: (4, 10) In [27]: psycopg2.__version__ Out[27]: '2.4.4 (dt dec pq3 ext)'Please provide an example of the problem, thanks.
-
Mariano
Hi again Daniele!
This is the code I've tried.
import psycopg2, psycopg2.extras
cnn = psycopg2.extras.DictConnection("user='postgres'")
cur = cnn.cursor()
cur.execute('select * from generate_series(1,10)')
for i in cur:print (cur.rownumber, cur.rowcount)
If I execute it with 2.4.2, with python2 and python3, I get:
(1, 10) (2, 10) (3, 10) (4, 10) (5, 10) (6, 10) (7, 10) (8, 10) (9, 10) (10, 10)If I execute it with 2.4.4, with python2 and python3, I get the error:
(10, 10) (10, 10) (10, 10) (10, 10) (10, 10) (10, 10) (10, 10) (10, 10) (10, 10) (10, 10)Thank you
-
Daniele Varrazzo
- State changed from new to open
I see: It's probably a regression introduced with this change, to make itersize work as expected.
https://github.com/dvarrazzo/psycopg/commit/8473209d240bad964630b9b...
Will see this evening how to fix it. The problem is shared by several cursor subclasses.
-
Daniele Varrazzo
- State changed from open to resolved
Fixed in my dev branch.
rownumber is still broken for named cursors though. This would be an entirely different correction, and they have been broken forever, so I'm not in hurry to fix them.