ClickHouse / ClickHouse/clickhouse-go
expected ... arguments, got ... when using db.Prepare()
- Dominant language
- Go
- Stars
- 3.3k
- Forks
- 680
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 14
Description
## Observed
The program below creates a table and tries to insert two rows into it. The first row is inserted using `db.Exec()` the second one using `stmt, err := db.Prepare()` + `stmt.Exec()`.
The insert using `db.Exec()` works, the insert using `stmt.Exec()` returns an error: `expected 3 arguments, got 2`
## Expected behaviour
I'd expect both inserts to work identically.
## Code example
```go
package main
import (
"database/sql"
"log"
_ "github.com/ClickHouse/clickhouse-go/v2"
)
func main() {
dsn := "https://clickhouse:443/test?secure=true&username=user&password=pass&debug=true"
db, err := sql.Open("clickhouse", dsn)
if err != nil {
log.Fatalf("failed to connect: %v", err)
}
_, err = db.Exec(`DROP TABLE example`)
if err != nil {
log.Fatalf("failed to drop table: %v", err)
}
_, err = db.Exec(`CREATE TABLE example (
a String,
b Nullable(String),
c Nullable(String)
) ENGINE = MergeTree PRIMARY KEY a
`)
if err != nil {
log.Fatalf("failed to create table: %v", err)
}
// This works
_, err = db.Exec(`INSERT INTO example(a, c) VALUES('foo','bar')`)
if err != nil {
log.Fatalf("exec failed: %w", err)
}
// This does not
stmt, err := db.Prepare(`INSERT INTO example(a, c) VALUES(?,?)`)
if err != nil {
log.Fatalf("prepare failed: %w", err)
}
_, err = stmt.Exec([]interface{} {"foo", "bar"}...)
if err != nil {
log.Fatalf("execution failed: %w", err)
}
}
```
## Error log
```log
[clickhouse-std][conn=0][clickhouse:443] [batch][exec] append error: clickhouse [Append]: clickhouse: expected 3 arguments, got 2
2025/01/31 03:54:10 execution failed: %!w(*proto.BlockError=&{Append 0xc000030250 })
exit status 1
```
## Details
### Environment
* `clickhouse-go` version: v2.30.1
* Interface: `database/sql` compatible driver
* Go version: go version go1.23.5 windows/amd64
* Operating system: Windows 10 Pro
* ClickHouse version: 24.12.3.47
* Is it a ClickHouse Cloud? No.
Contributor guide
Research direction
Start by running the supplied Go reproduction against the database/sql-compatible driver, focusing on the db.Prepare and stmt.Exec entry points. Trace why the prepared INSERT reports three expected arguments for two placeholders, then verify that prepared and direct inserts behave consistently without the argument-count error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clickhouse, go
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100