Skip to content

Commit

Permalink
Add a write into file example (ClickHouse#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
slvrtrn authored Dec 16, 2024
1 parent dd9c9db commit 29d61e9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/write_into_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import clickhouse_connect

if __name__ == '__main__':
client = clickhouse_connect.get_client()
query = 'SELECT number, toString(number) AS number_as_str FROM system.numbers LIMIT 5'
fmt = 'CSVWithNames' # or any other format, see https://clickhouse.com/docs/en/interfaces/formats
stream = client.raw_stream(query=query, fmt=fmt)
with open("output.csv", "wb") as f:
for chunk in stream:
f.write(chunk)

0 comments on commit 29d61e9

Please sign in to comment.