Skip to content

LowCardinality(Nullable(String)) type support #68

@mavr

Description

@mavr

I expect no errors while inserting struct below, but instead I get error unsupported ClickHouse column

package main

import (
	"context"
	"fmt"
	"reflect"

	"github.com/uptrace/go-clickhouse/ch"
)

type Address string

type ProblemStruct struct {
	S *string `ch:"type:LowCardinality(Nullable(String))"`
}

func main() {
	example := "example"
	var v = ProblemStruct{
		S: &example,
	}

	dsnCH := "clickhouse://localhost:9000/default?sslmode=disable"
	chDB := ch.Connect(
		ch.WithDSN(dsnCH), ch.WithAutoCreateDatabase(true), ch.WithPoolSize(16))

	_, err := chDB.NewDropTable().
		Model(new(ProblemStruct)).
		IfExists().
		Exec(context.Background())
	if err != nil {
		panic(err)
	}

	_, err = chDB.NewCreateTable().
		Model(new(ProblemStruct)).
		IfNotExists().
		Engine("ReplacingMergeTree").
		Exec(context.Background())
	if err != nil {
		panic(err)
	}

	_, err = chDB.NewInsert().Model(&v).Exec(context.Background())
	if err != nil {
		panic(err)
	}

	var got ProblemStruct

	err = chDB.NewSelect().Model(&got).Scan(context.Background())
	if err != nil {
		panic(err)
	}

	if !reflect.DeepEqual(v, got) {
		fmt.Printf("expected: %+v", v)
		fmt.Printf("got: %+v", v)
		panic(nil)
	}
}

Version: go-clickhouse v0.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions