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

批量插入CreateInBatches异常 #92

Open
gcggcg opened this issue Mar 15, 2023 · 2 comments
Open

批量插入CreateInBatches异常 #92

gcggcg opened this issue Mar 15, 2023 · 2 comments
Assignees

Comments

@gcggcg
Copy link

gcggcg commented Mar 15, 2023

GORM Playground Link

`m := []UserTable{
{User: User{
Name: "tom1",
Age: 12,
Class: 10,
}},
{User: User{
Name: "li1",
Age: 22,
Class: 10,
}},
{User: User{
Name: "wang1",
Age: 22,
Class: 10,
}},
{User: User{
Name: "wan",
Age: 22,
Class: 10,
}},
}

if err = db.Model(&UserTable{}).CreateInBatches(&m,2).Error; err != nil {
	fmt.Println("插入数据异常: ", err)
}`

Description

当指定批量插入按照2条数据一组,进行批量插入,一共四条数据gorm底层库会分两批插入,但是发现clickhouse库会失败异常,具体原因可以使用的方式是: 如果指定批量插入的数据量必须大于总插入数据量进行一次性插入可以成功,一旦设置小于总量就会报错,请重点关注一下,这个异常不符合实际需求。

异常响应: code: 101, message: Unexpected packet Query received from client

@CodFrm
Copy link

CodFrm commented Mar 17, 2023

我大于总量也报错

后面将Session(&gorm.Session{SkipDefaultTransaction: true}).去了,没遇到了

batchSize设置为了实际数据长度+1

@tkq1994
Copy link

tkq1994 commented Mar 22, 2024

蹲一个解决办法,小于总数据量会报;code: 101, message: Unexpected packet Query received from client

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

4 participants