Advanced Inserting

# When queried back, the time is automatically converted to Los Angeles timezone
# 10:30 AM New York (UTC-4) = 14:30 UTC = 7:30 AM Los Angeles (UTC-7)
results = client.query("select * from events")
print(*results.result_rows, sep="\n")
# Output:
# (datetime.datetime(2023, 6, 15, 7, 30, tzinfo=<DstTzInfo 'America/Los_Angeles' PDT-1 day, 17:00:00 DST>),)
```

## File inserts[​](#file-inserts "Direct link to File inserts")

The `clickhouse_connect.driver.tools` package includes the `insert_file` method that allows inserting data directly from the file system into an existing ClickHouse table. Parsing is delegated to the ClickHouse server. `insert_file` accepts the following parameters:

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Parameter Type Default Description|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | client Client *Required* The `driver.Client` used to perform the insert| table str *Required* The ClickHouse table to insert into. The full table name (including database) is permitted.|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | file\_path str *Required* The native file system path to the data file|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | fmt str CSV, CSVWithNames The ClickHouse Input Format of the file. CSVWithNames is assumed if `column_names` isn't provided| column\_names Sequence of str *None* A list of column names in the data file. Not required for formats that include column names|  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | database str *None* Database of the table. Ignored if the table is fully qualified. If not specified, the insert will use the client database|  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | | settings dict *None* See [settings description](/docs/integrations/language-clients/python/driver-api#settings-argument).| compression str *None* A recognized ClickHouse compression type (zstd, lz4, gzip) used for the Content-Encoding HTTP header | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

For files with inconsistent data or date/time values in an unusual format, settings that apply to data imports (such as `input_format_allow_errors_num` and `input_format_allow_errors_num`) are recognized for this method.

```
import clickhouse_connect
from clickhouse_connect.driver.tools import insert_file

client = clickhouse_connect.get_client()
insert_file(client, 'example_table', 'my_data.csv',
            settings={'input_format_allow_errors_ratio': .2,
                      'input_format_allow_errors_num': 5})
```

- [Inserting data with ClickHouse Connect: Advanced usage](#inserting-data-with-clickhouse-connect--advanced-usage)
  - [InsertContexts](#insertcontexts)- [Write formats](#write-formats)- [Specialized insert methods](#specialized-insert-methods)- [Time zones](#time-zones)- [File inserts](#file-inserts)

Was this page helpful?