forked from danielkurniadi/clickhouse
-
-
Notifications
You must be signed in to change notification settings - Fork 75
Open
Description
When using gorm.io/driver/clickhouse together with clickhouse-go/v2, running the following query:
db.Raw("SELECT currentDatabase()").Scan(&name)
results in this error:
invalid INSERT query: SELECT currentDatabase()
This is unexpected because the query is clearly a SELECT, not an INSERT.
Expected behavior
The query SELECT currentDatabase() should execute without error and return the current database name.
Actual behavior
The query is incorrectly classified as an INSERT and fails with:
invalid INSERT query: SELECT currentDatabase()
Reproduction steps
package main
import (
"database/sql"
"fmt"
_ "github.com/ClickHouse/clickhouse-go/v2"
)
func main() {
dsn := "clickhouse://default:@localhost:9000/default"
db, err := sql.Open("clickhouse", dsn)
if err != nil {
panic(err)
}
query := "SELECT currentDatabase()"
var dbName string
if err := db.QueryRow(query).Scan(&dbName); err != nil {
panic(fmt.Errorf("error: %w", err))
}
fmt.Println("Current DB:", dbName)
}
Works with sql.DB().QueryRow(...)
Fails with GORM's db.Raw(...).Scan(...)
Environment
Go version: go1.23.8
clickhouse-go version: v2.37.2
GORM version: v1.30.0
OS: macOS
Metadata
Metadata
Assignees
Labels
No labels