Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LowCardinality(Nullable(String)) type support #68

Open
mavr opened this issue Jul 5, 2023 · 2 comments
Open

LowCardinality(Nullable(String)) type support #68

mavr opened this issue Jul 5, 2023 · 2 comments

Comments

@mavr
Copy link

mavr commented Jul 5, 2023

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

@vmihailenco
Copy link
Member

You can try Nullable(LowCardinality(String)). I am not sure what the difference is.

@mavr
Copy link
Author

mavr commented Jul 6, 2023

Thanks @vmihailenco.
Perhaps this could be a solution, but I need to integrate with an already existing schema. And this one uses LowCardinality(Nullable(String))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants