Skip to content

Instantly share code, notes, and snippets.

@kavirajk
Created November 11, 2025 07:41
Show Gist options
  • Select an option

  • Save kavirajk/81428effcb2a59bc4eadc03053ac8d36 to your computer and use it in GitHub Desktop.

Select an option

Save kavirajk/81428effcb2a59bc4eadc03053ac8d36 to your computer and use it in GitHub Desktop.
Query Params clickhouse-go
package main
import (
"context"
"fmt"
"os"
"github.com/ClickHouse/clickhouse-go/v2"
)
func main() {
conn, err := clickhouse.Open(&clickhouse.Options{
Protocol: clickhouse.HTTP,
Addr: []string{"localhost:8123"},
})
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to connect: %v\n", err)
os.Exit(1)
}
defer conn.Close()
chCtx := clickhouse.Context(context.Background(), clickhouse.WithParameters(clickhouse.Parameters{
"array": "['a', 'b', 'c', 'hello', 'testing']",
"column": "number",
"database": "system",
"table": "numbers",
}))
row := conn.QueryRow(chCtx, "SELECT {column:Identifier} v, {array:Array(String)} a FROM {database:Identifier}.{table:Identifier} LIMIT 1 OFFSET 100")
var (
col1 uint64
col3 []string
)
if err := row.Scan(&col1, &col3); err != nil {
panic(err)
}
fmt.Printf("row: col1=%d, col3=%s\n", col1, col3)
}
@kavirajk
Copy link
Author

$ go run query_params.go
row: col1=100, col3=[a b c hello testing]
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment