Skip to content

Conversation

stephennancekivell
Copy link

Hi folks, im having trouble with bulk inserts into clickhouse. NamedExec queries are only getting the first value in the array.

This PR fixes the issue by extending the regex to support settings.

Eg this test case fails, with only joe getting inserted, not sally.

func TestInsertNamedBulk(t *testing.T) {
	_, err := db.Exec(schema)
	assert.NoError(t, err)
	defer cleanup(t)

	// Insert data
	_, err = db.NamedExec(
		`insert into users (id, name, age)
		SETTINGS async_insert=1, wait_for_async_insert=1
		values
		(:id, :name, :age)`,
		[]map[string]any{
			{
				"id":   1,
				"name": "joe",
				"age":  30,
			},
			{
				"id":   2,
				"name": "sally",
				"age":  31,
			},
		})
	assert.NoError(t, err)

	users, err := findUsers()
	assert.NoError(t, err)
	assert.Equal(t, []User{
		{ID: 1, Name: "joe", Age: 30},
		{ID: 2, Name: "sally", Age: 31},
	}, users)
}

@stephennancekivell stephennancekivell changed the title Add support for clickhouse settings Add support for clickhouse settings in NamedExec's fixBounds Oct 4, 2024
@mrj0
Copy link

mrj0 commented Feb 6, 2025

I think this one would also solve your problem without adding db-specific patterns to the regex: https://github.com/jmoiron/sqlx/pull/962/files

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 this pull request may close these issues.

2 participants