[问题] 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