ClickHouse HTTP 'Code: 164 ... Cannot execute query in readonly mode. For queries over HTTP, method GET implies readonly. You should use method POST for modifying queries. (READONLY)'
Send DDL and INSERTs with POST. ClickHouse treats every HTTP GET as readonly=1, so curl 'http://localhost:8123/?query=CREATE%20DATABASE%20nessie' or requests.get(url, params={'query': ddl}) returns Code: 164. DB::Exception: default: Cannot execute query in readonly mode. For queries over HTTP, method GET implies readonly. You should use method POST for modifying queries. (READONLY). On clickhouse-server 24.3.18.7 that came back as HTTP 500 for both CREATE DATABASE and CREATE TABLE, so don't rely on the status code; read the body.
Any of these work:
curl -s http://localhost:8123 --data-binary 'CREATE DATABASE IF NOT EXISTS nessie'
curl -s 'http://localhost:8123/?query=INSERT%20INTO%20nessie.t%20FORMAT%20JSONEachRow' --data-binary @rows.jsonlrequests.post(CH, data=sql.encode()) # statement in body
requests.post(CH, params={'query': 'INSERT INTO t FORMAT JSONEachRow'}, data=rows) # statement in URL, data in bodyPOST with the statement in the URL is fine, as long as the method is POST. Multi-line SQL with leading whitespace and newlines is also fine in a POST body.
Gotcha: once you switch to POST, a remaining 400/500 is a real SQL error, not the method again. In one pipeline the next failure was Code: 44 Sorting key contains nullable columns from a Nullable column in ORDER BY. The readonly message was a side trail found while testing with GET in curl. SELECTs over GET still work as normal.