ClickHouse / ClickHouse/clickhouse-go

Query Parameters not working in INSERT statement

Open
#1,703 1 comment 0 reactions 0 assignees View on GitHub
bug docs investigate Q1-FY-2026 query-params
Dominant language
Go
Stars
3.3k
Forks
684
Avg merge
2d 3h
Merged PRs (30d)
14

Description

## Observed

An `INSERT INTO` query using query parameters, like `INSERT INTO test_table ({col:Identifier}) ...`, fails with an error as if the placeholder is replaced with an empty string, rather than the given value:

```panic: code: 62, message: Syntax error: failed at position 41 ()): ) SELECT {str:String} FROM system.numbers LIMIT 100.```

## Expected behaviour

It should replace the query parameter with an identifier specified by the provided parameters.

## Code example

```go
func InsertQueryWithParameters() {
dsn := env.GetString("CLICKHOUSE_DSN", "clickhouse://user:pass@localhost:9000")
copts, err := clickhouse.ParseDSN(dsn)
if err != nil {
panic(err)
}
conn, err := clickhouse.Open(copts)
if err != nil {
panic(err)
}

chCtx := clickhouse.Context(context.Background(), clickhouse.WithParameters(clickhouse.Parameters{
"str": "hello",
"col": "val",
}))
err = conn.Exec(chCtx, "CREATE TABLE IF NOT EXISTS test_table (val String) ENGINE = Memory")
if err != nil {
panic(err)
}

// Works:
err = conn.Exec(chCtx, "INSERT INTO test_table (val) SELECT {str:String} FROM system.numbers LIMIT 100")
if err != nil {
panic(err)
}

// Doesn't work:
err = conn.Exec(chCtx, "INSERT INTO test_table ({col:Identifier}) SELECT {str:String} FROM system.numbers LIMIT 100")
if err != nil {
panic(err)
}
return
}

func main() {
InsertQueryWithParameters()
}
```

## Error log

This is the output of the example program above:

```log
panic: code: 62, message: Syntax error: failed at position 41 ()): ) SELECT {str:String} FROM system.numbers LIMIT 100. Expected one of: token sequence, Dot, token
```

## Details

### Environment
* [x] `clickhouse-go` version: v2.40.3
* [x] Interface: ClickHouse API / `database/sql` compatible driver
* [x] Go version: `go version go1.25.3 darwin/arm64`
* [x] Operating system: MacOS
* [x] ClickHouse version: `25.6.13`
* [x] Is it a ClickHouse Cloud? No
* [x] ClickHouse Server non-default settings, if any: N/A
* [x] `CREATE TABLE` statements for tables involved: See example code
* [x] Sample data for all these tables, use [clickhouse-obfuscator](https://github.com/ClickHouse/ClickHouse/blob/master/programs/obfuscator/Obfuscator.cpp#L42-L80) if necessary

Contributor guide

Open the contributing guide

Research direction

Start with the InsertQueryWithParameters example and compare the working INSERT statement with the version using {col:Identifier}. Trace the conn.Exec path with clickhouse.WithParameters and the provided col and str values. Done means the identifier parameter is substituted so the INSERT executes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.