[問題] psycopg2 itersize參數問題

看板Python作者 (BLG_Eric)時間6年前 (2018/09/23 01:57), 編輯推噓2(205)
留言7則, 2人參與, 6年前最新討論串1/1
小弟我知道這個參數的用途 但是有一部份的程式邏輯不是很清楚 因此想請問 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

09/23 15:53, 6年前 , 1F
itersize : Read/write attribute specifying the numbe
09/23 15:53, 1F

09/23 15:53, 6年前 , 2F
r of rows to fetch from the backend at each network
09/23 15:53, 2F

09/23 15:53, 6年前 , 3F
roundtrip during iteration on a named cursor. The d
09/23 15:53, 3F

09/23 15:53, 6年前 , 4F
efault is 2000.
09/23 15:53, 4F

09/23 15:54, 6年前 , 5F
文件是寫網路溝通底層一輪處理的數量
09/23 15:54, 5F

09/23 15:56, 6年前 , 6F
你的需求應該是使用 fetchmany(10000)
09/23 15:56, 6F

09/23 22:01, 6年前 , 7F
好的 感謝Ken大解釋
09/23 22:01, 7F
文章代碼(AID): #1RfeA7_3 (Python)
文章代碼(AID): #1RfeA7_3 (Python)