Din kod bör se ut som nedan. Du kan justera dess prestanda med per_query
variabel
c = csv.writer(open("temp.csv","wb"))
offset = 0
per_query = 10000
while true:
cur.execute("__the_query__ LIMIT %s OFFSET %s", (per_query, offset))
rows = cur.fetchall()
if len(rows) == 0:
break #escape the loop at the end of data
for row in cur.fetchall():
c.writerow(row)
offset += per_query