Skip to content

Instantly share code, notes, and snippets.

@kavirajk
Last active January 14, 2026 16:12
Show Gist options
  • Select an option

  • Save kavirajk/1a751838ea9154c002a644bcd8e7cf2a to your computer and use it in GitHub Desktop.

Select an option

Save kavirajk/1a751838ea9154c002a644bcd8e7cf2a to your computer and use it in GitHub Desktop.
Variant type broken on `head` CH
package main
import (
"context"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2"
)
func main() {
conn, err := clickhouse.Open(&clickhouse.Options{
Addr: []string{"localhost:9000"},
})
if err != nil {
panic(err)
}
ctx := context.Background()
const ddl = `
CREATE OR REPLACE TABLE test_dynamic_exceeded_types (
c Dynamic
) Engine = MergeTree() ORDER BY tuple()
`
if err := conn.Exec(ctx, ddl); err != nil {
panic(err)
}
testTypeCount := func(typeCount int) func() error {
return func() error {
batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_dynamic_exceeded_types (c)")
if err != nil {
return err
}
for i := range typeCount {
typeName := fmt.Sprintf("Tuple(\"%d\" Int64)", i)
if err := batch.Append(clickhouse.NewDynamicWithType([]int64{int64(i)}, typeName)); err != nil {
return err
}
}
if err := batch.Send(); err != nil {
return err
}
rows, err := conn.Query(ctx, "SELECT c FROM test_dynamic_exceeded_types")
if err != nil {
return err
}
if err := rows.Close(); err != nil {
return err
}
if err := rows.Err(); err != nil {
return err
}
return nil
}
}
if err := testTypeCount(300)(); err != nil {
panic(err)
}
}
@kavirajk
Copy link
Author

Setup

Failing with clickhouse-server:head

$ docker run -d -p 9000:9000 -e  CLICKHOUSE_SKIP_USER_SETUP=1 clickhouse/clickhouse-server:head

$ go run variant_fail.go
panic: code: 36, message: Variant type with more than 255 nested types is not allowed

goroutine 1 [running]:
main.main()
	/home/kavi/src/play-go2/variant_fail.go:61 +0x325
exit status 2

Passing in clickhouse-server:25.12

$ docker stop $(docker ps -q)

$ docker run -d -p 9000:9000 -e  CLICKHOUSE_SKIP_USER_SETUP=1 clickhouse/clickhouse-server:25.12

$ go run variant_fail.go

$ clickhouse-client --query "SELECT count() FROM test_dynamic_exceeded_types"
300

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