-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http stdBatch AppendRow assumes table columns and insert field order is the same #741
Comments
Nice catch, will fix in 2.4.0. |
...a similar issue happens if you try to insert only a subset of columns, the error is different but the cause is the same
|
This is quite tricky in native since we effectively send I'll PR. |
i think we'll sort the block according to the requested order. PR today. |
and what would happen if there's only a subset of the columns? |
responds with just those - this is native protocol behavior though. HTTP is different and will need a different approach. |
just to be clear: this particular issue is about the HTTP wire protocol. I don't know what "FORMAT Native" means in the HTTP request clickhouse-go makes but it inserts successfully if all rows are present and ordered the same as the table definition. I can't reach that particular ClickHouse instance via native TCP |
there is native format and native protocol. We always use native format, but user can choose between native protocol and http. |
Ah I see, thanks for the explanation |
Had an opportunity to test, can confirm it works with 2.4.3 |
Issue description
When insert order and column order is different, the driver tries to match them by index and fails on the first incompatible column type
So when the prepared statement with
INSERT INTO table1 (col2int, col1string) VALUES (? ?)
gets optimized intoINSERT INTO table1 FORMAT Native
the insert fails.Workaround: specify fields in the order exactly as is currently in the table
Proposed fix: don't add fields in prepareBatch as-is but respect the field order (and what fields are present) from the query. See https://github.com/ClickHouse/clickhouse-go/blob/main/conn_http_batch.go#L65
Steps to reproduce
CREATE TABLE table1 (col1string String, col2int Int64)
INSERT INTO table1 (col2int, col1string) VALUES (? ?)
stmt.Exec(5, "abc")
Error log
Configuration
OS: osx monterey
Interface:
database/sql
Driver version: clickhouse-go 2.3.0
Go version: 1.18.5
ClickHouse Server version: 22.8.1.1316
The text was updated successfully, but these errors were encountered: