作者BlgAtlfans (BLG_Eric)
看板Python
標題[問題] psycopg2 itersize參數問題
時間Sun Sep 23 01:57:24 2018
小弟我知道這個參數的用途
但是有一部份的程式邏輯不是很清楚
因此想請問
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筆的資料
想請問我的想法哪裡錯了?
感謝各位高手指導
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.193.176.122
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1537639047.A.FC3.html
推 kenduest: itersize : Read/write attribute specifying the numbe 09/23 15:53
→ kenduest: r of rows to fetch from the backend at each network 09/23 15:53
→ kenduest: roundtrip during iteration on a named cursor. The d 09/23 15:53
→ kenduest: efault is 2000. 09/23 15:53
→ kenduest: 文件是寫網路溝通底層一輪處理的數量 09/23 15:54
推 kenduest: 你的需求應該是使用 fetchmany(10000) 09/23 15:56
→ BlgAtlfans: 好的 感謝Ken大解釋 09/23 22:01