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

happen error in create. print error [unsupported data type: &[]] #105

Open
Gpihuier opened this issue Apr 26, 2023 · 1 comment
Open

happen error in create. print error [unsupported data type: &[]] #105

Gpihuier opened this issue Apr 26, 2023 · 1 comment
Assignees

Comments

@Gpihuier
Copy link

creare data to clickhouse happen error but data success write to clickhouse

2023/04/26 10:58:22 main.go:32
[error] unsupported data type: &[]
Ok

version info

go version: go version go1.20.3 linux/amd64
clickhouse version: 23.3.1.2823
gorm version: gorm@v1.25.0
driver clickhouse: v0.5.1

pseudocode:

package main

import (
	"fmt"

	"gorm.io/driver/clickhouse"
	"gorm.io/gorm"
)

type User struct {
	Uniqid string `gorm:"column:uniqid;primaryKey"`
	Name   string `gorm:"column:name"`
}

func (User) TableName() string {
	return "user"
}

func main() {

	dsn := "clickhouse://gorm:gorm@localhost:9942/gorm?dial_timeout=10s&read_timeout=20s"
	db, err := gorm.Open(clickhouse.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}

	u := User{
		Uniqid: "31502ca1839f3dccd849abdc49e2fa41",
		Name:   "gorm",
	}

	err = db.Table("user").Create(&u).Error
	if err != nil {
		panic(err)
	}

	fmt.Println("Ok")
}

// Output
// 2023/04/26 10:58:22 main.go:32
// [error] unsupported data type: &[]
// Ok
@taomin597715379
Copy link

[error] unsupported data type: &[] 这个错误一般是因为model里面定义了一些非基本类型的数据结构,如[]string,map等,涉及到这类的数据结构时,这类的数据结构需要实现GormDataTypeInterface接口,就不会报这类错误了

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

3 participants