[問題] psycopg2 itersize參數問題

作者: BlgAtlfans (BLG_Eric)   2018-09-23 01:57:24
小弟我知道這個參數的用途
但是有一部份的程式邏輯不是很清楚
因此想請問
import psycopg2 as pg
conn = pg.connect('string')
cursor = conn.cursor('name')
cursor.itersize = 10000
cursor.execute('sql_command LIMIT 1000000')
照理說這時候cursor的執行方式應該是
以一次10000筆的方式回傳sql執行的結果
但是如果我底下接著用
cursor.fetchall()
應該要抓到10000筆的資料才對
但是結果吐出的卻是1000000筆的資料
想請問我的想法哪裡錯了?
感謝各位高手指導
作者: kenduest (小州)   2018-09-23 15:53:00
itersize : Read/write attribute specifying the number of rows to fetch from the backend at each networkroundtrip during iteration on a named cursor. The default is 2000.文件是寫網路溝通底層一輪處理的數量你的需求應該是使用 fetchmany(10000)
作者: BlgAtlfans (BLG_Eric)   2018-09-23 22:01:00
好的 感謝Ken大解釋

Links booklink

Contact Us: admin [ a t ] ucptt.com