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

AppendStruct() and Tuple support #1010

Closed
topofstack opened this issue Jun 9, 2023 · 2 comments · Fixed by #1500
Closed

AppendStruct() and Tuple support #1010

topofstack opened this issue Jun 9, 2023 · 2 comments · Fixed by #1500

Comments

@topofstack
Copy link

topofstack commented Jun 9, 2023

Hi, looks like AppendStruct API does not support structs with nested fields. Here's an extended version of official example:

type Nested struct {
	Foo int64
}

type Row struct {
	Col1       uint64
	Col4       time.Time
	Col2       string
	Col3       []uint8
	Col5       *Nested
	ColIgnored string
}

func TestAppendStructInsert() {
	conn, err := OpenDB()
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()

	if err := conn.Exec(ctx, `DROP TABLE IF EXISTS example`); err != nil {
		log.Fatal(err)
	}

	if err := conn.Exec(ctx, `
		CREATE TABLE example (
			  Col1 UInt64
			, Col2 String
			, Col3 Array(UInt8)
			, Col4 DateTime
			, Col5 Tuple(Foo Int64)
		) Engine = Memory
		`); err != nil {
		log.Fatal(err)
	}

	batch, err := conn.PrepareBatch(context.Background(), "INSERT INTO example")
	if err != nil {
		log.Fatal(err)
	}

	err = batch.AppendStruct(&Row{
		Col1:       uint64(100),
		Col2:       "Golang SQL database driver",
		Col3:       []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9},
		Col4:       time.Now(),
		ColIgnored: "this will be ignored",
		Col5: &Nested{
			Foo: 1000000,
		},
	})
	if err != nil {
		log.Fatal(err)
	}
}

The message I get says:
clickhouse [AppendRow]: Col5 clickhouse [AppendRow]: converting *main.Nested to Tuple(Foo Int64) is unsupported

Is there any workaround or any future plans to support this feature?

@spaghettifunk
Copy link

spaghettifunk commented Apr 25, 2024

Having the same issue but with a different error. I receive clickhouse [AppendStruct]: missing destination name <column_name> in *<struct>. However, instead of using a Tuple I use Nested. Did you figure out a workaround?

@mehXX
Copy link

mehXX commented Dec 26, 2024

@spaghettifunk have you found the solution for this?

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

Successfully merging a pull request may close this issue.

3 participants