From 29d61e99d9c4e9d02fb36180fd6b58bbce482cc5 Mon Sep 17 00:00:00 2001 From: Serge Klochkov <3175289+slvrtrn@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:08:00 +0100 Subject: [PATCH] Add a write into file example (#437) --- examples/write_into_file.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 examples/write_into_file.py diff --git a/examples/write_into_file.py b/examples/write_into_file.py new file mode 100644 index 00000000..e927ac57 --- /dev/null +++ b/examples/write_into_file.py @@ -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)