clickhouse-connect
clickhouse-connect copied to clipboard
Httpclient error when executing INSERT INTO with LIMIT 0
Describe the bug
When I execute an INSERT INTO
command using the httpclient, it returns an error if the insert query contains LIMIT 0
.
Steps to reproduce
- Create a table in Clickhouse or Clickhouse cloud
- Use the httpclient to execute an
INSERT INTO
command whose query containsLIMIT 0
Expected behaviour
No error. (I realize that inserting the results of a query that returns no rows is pointless, but here we are.)
Code example
> self.execute("CREATE OR REPLACE TABLE test_insert (col1 Int8) order by ();")
> self.execute("INSERT INTO test_insert SELECT 1 LIMIT 0;")
Traceback (most recent call last):
File ".venv/lib/python3.11/site-packages/clickhouse_connect/dbapi/cursor.py", line 56, in execute
query_result = self.client.query(operation, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/clickhouse_connect/driver/client.py", line 209, in query
return self._query_with_context(query_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/clickhouse_connect/driver/httpclient.py", line 210, in _query_with_context
for col in json_result['meta']:
^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'json_result' where it is not associated with a value
Executing the same INSERT INTO
query without LIMIT 0
works as expected and nothing is printed to terminal:
> self.execute("INSERT INTO test_insert SELECT 1;")
Configuration
Environment
- clickhouse-connect version: 0.7.18
- Python version: 3.11.6
- Operating system: MacOS Ventura 13.4.1
ClickHouse server
- ClickHouse Server version: 24.7.3.42