Stream results to disk rather than memory? #327
Replies: 1 comment
-
Yes, instead of using e.g. cursor.arraysize = 100
# only 100 rows will be fetched at a time
cursor.execute("SELECT * FROM tpch.sf1.orders")
with open(csv_file, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
rows = cursor.fetchmany()
# get column names
headers = [desc[0] for desc in cursor.description]
write.writerow(headers)
# write rows
while len(rows) > 0:
writer.writerows(rows)
rows = cursor.fetchmany() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My app needs to write a large result to file. Is there a way to do this without capturing results in memory?
Beta Was this translation helpful? Give feedback.
All reactions