sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Add support for clickhouse settings in NamedExec's fixBounds

Open stephennancekivell opened this issue 1 year ago • 1 comments

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 avatar Oct 04 '24 03:10 stephennancekivell

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

mrj0 avatar Feb 06 '25 05:02 mrj0