Skip to content

Commit 03cb115

Browse files
authored
Fix column name with parantheses handle in prepare batch (#1252)
* Fix column name with parantheses handle in prepare batch * fix test
1 parent d79a61c commit 03cb115

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

conn_batch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
)
3434

3535
var splitInsertRe = regexp.MustCompile(`(?i)\sVALUES\s*\(`)
36-
var columnMatch = regexp.MustCompile(`.*\((?P<Columns>.+)\)$`)
36+
var columnMatch = regexp.MustCompile(`INSERT INTO .+\s\((?P<Columns>.+)\)$`)
3737

3838
func (c *connect) prepareBatch(ctx context.Context, query string, opts driver.PrepareBatchOptions, release func(*connect, error), acquire func(context.Context) (*connect, error)) (driver.Batch, error) {
3939
//defer func() {

tests/issues/1247_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package issues
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/ClickHouse/clickhouse-go/v2"
8+
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func Test1247(t *testing.T) {
13+
var (
14+
conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{
15+
"max_execution_time": 60,
16+
"allow_experimental_object_type": true,
17+
}, nil, &clickhouse.Compression{
18+
Method: clickhouse.CompressionLZ4,
19+
})
20+
)
21+
ctx := context.Background()
22+
require.NoError(t, err)
23+
const ddl = "CREATE TABLE test_1247 (`ColumnNameWithParentheses(something)` String) Engine MergeTree() ORDER BY tuple()"
24+
require.NoError(t, conn.Exec(ctx, ddl))
25+
defer func() {
26+
conn.Exec(ctx, "DROP TABLE IF EXISTS test_1247")
27+
}()
28+
29+
_, err = conn.PrepareBatch(context.Background(), "INSERT INTO test_1247 (`ColumnNameWithParentheses(something)`)")
30+
require.NoError(t, err)
31+
}

0 commit comments

Comments
 (0)