-
Notifications
You must be signed in to change notification settings - Fork 615
Open
Labels
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
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:
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
-
clickhouse-goversion: v2.40.3 - Interface: ClickHouse API /
database/sqlcompatible driver - Go version:
go version go1.25.3 darwin/arm64 - Operating system: MacOS
- ClickHouse version:
25.6.13 - Is it a ClickHouse Cloud? No
- ClickHouse Server non-default settings, if any: N/A
-
CREATE TABLEstatements for tables involved: See example code - Sample data for all these tables, use clickhouse-obfuscator if necessary