ClickHouse / ClickHouse/clickhouse-go

QueryContext not supported in prepared statement in SQL driver compatibility

Open
#1,203 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
3.3k
Forks
680
Avg merge
2d 3h
Merged PRs (30d)
14

Description

### Describe the bug

When executing a prepared query statement, the SQL client returns `only Exec method supported in batch mode`.

### Steps to reproduce
1. `docker run --name clickhouse -p 9000:9000 -e ALLOW_EMPTY_PASSWORD=yes bitnami/clickhouse`
2. wait for container to startup
3. `go run main.go`

### Expected behaviour

Query is executed and rows are returned without an error.

### Code example
```go
package main

import (
"context"
"database/sql"
"fmt"
"log"

_ "github.com/ClickHouse/clickhouse-go/v2"
)

func main() {
db, err := sql.Open("clickhouse", "clickhouse://default@127.0.0.1:9000")
if err != nil {
log.Fatalf("opening database failed: %v", err)
}
defer db.Close()

ctx := context.Background()
if err := db.PingContext(ctx); err != nil {
log.Printf("pinging server failed: %v", err)
}

stmt, err := db.PrepareContext(ctx, "SELECT * FROM system.metrics")
if err != nil {
log.Fatalf("preparing statement failed: %v", err)
}

rows, err := stmt.QueryContext(ctx)
if err != nil {
log.Fatalf("executing preparing statement failed: %v", err)
}
columns, err := rows.Columns()
fmt.Println("row columns:", columns)
fmt.Println("err:", err)
}
```

### Configuration
#### Environment
* Client version: 2.18.0
* Language version: Golang
* OS: Linux/AMD64
* Interface: ClickHouse database/sql compatible driver

#### ClickHouse server
* ClickHouse Server version: tested with 22.x, 23.8 and latest

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided ClickHouse Docker command and go run main.go, then inspect the database/sql compatibility path around PrepareContext and QueryContext. The work is done when the prepared query returns rows without the batch-mode error; the payload does not name a specific file or regression test.

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.