From db932b2a071fba05790fe10ce6f9db6f2cc894dc Mon Sep 17 00:00:00 2001 From: Matthew Summers <246615743+brimleylabs@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:30:21 -0600 Subject: [PATCH] Fix panic preparing an INSERT with bare parameters into a Dolt system table A bare parameter takes its destination column's type, which is a GMS type for Dolt system tables. AssignInsertCasts then called String() on a nil type. Convert GMS types the same way the destination columns are converted, and name the real type in the error. --- server/analyzer/assign_insert_casts.go | 14 ++++++++++++-- testing/go/prepared_statement_test.go | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/server/analyzer/assign_insert_casts.go b/server/analyzer/assign_insert_casts.go index 21d89a8509..e8053cb605 100644 --- a/server/analyzer/assign_insert_casts.go +++ b/server/analyzer/assign_insert_casts.go @@ -78,7 +78,13 @@ func AssignInsertCasts(ctx *sql.Context, a *analyzer.Analyzer, node sql.Node, sc } fromColType, ok := colExprType.(*pgtypes.DoltgresType) if !ok { - return nil, transform.NewTree, errors.Errorf("INSERT: non-Doltgres type found in values source: %s", fromColType.String()) + // A parameter takes the type of its destination column, which is a GMS type for non-Doltgres tables + // (such as system tables), so it is converted the same way as the destination types above. + var err error + fromColType, err = pgtypes.FromGmsTypeToDoltgresType(colExprType) + if err != nil { + return nil, transform.NewTree, errors.Errorf("INSERT: non-Doltgres type found in values source: %s", colExprType.String()) + } } toColType := destinationTypes[columnIndex] // We only assign the existing expression if the types perfectly match (same parameters), otherwise we'll cast @@ -104,7 +110,11 @@ func AssignInsertCasts(ctx *sql.Context, a *analyzer.Analyzer, node sql.Node, sc } fromColType, ok := colType.(*pgtypes.DoltgresType) if !ok { - return nil, transform.NewTree, errors.Errorf("INSERT: non-Doltgres type found in source: %s", colType.String()) + var err error + fromColType, err = pgtypes.FromGmsTypeToDoltgresType(colType) + if err != nil { + return nil, transform.NewTree, errors.Errorf("INSERT: non-Doltgres type found in source: %s", colType.String()) + } } toColType := destinationTypes[i] var getField sql.Expression = expression.NewGetField(i, fromColType, col.Name, true) diff --git a/testing/go/prepared_statement_test.go b/testing/go/prepared_statement_test.go index e2e05a124e..9dde1baa43 100755 --- a/testing/go/prepared_statement_test.go +++ b/testing/go/prepared_statement_test.go @@ -32,6 +32,29 @@ func TestPreparedPgCatalog(t *testing.T) { } var preparedStatementTests = []ScriptTest{ + { + Name: "Insert into a Dolt system table with bare parameters", + Assertions: []ScriptTestAssertion{ + { + Query: "INSERT INTO dolt_nonlocal_tables (table_name, target_ref, ref_table, options) VALUES ($1, $2, $3, $4)", + BindVars: []any{"cache_%", "main", "", "immediate"}, + Expected: []sql.Row{}, + }, + { + Query: "INSERT INTO dolt_ignore (pattern, ignored) VALUES ($1, $2)", + BindVars: []any{"scratch_%", true}, + Expected: []sql.Row{}, + }, + { + Query: "SELECT table_name, target_ref, options FROM dolt_nonlocal_tables", + Expected: []sql.Row{{"cache_%", "main", "immediate"}}, + }, + { + Query: "SELECT pattern, ignored FROM dolt_ignore", + Expected: []sql.Row{{"scratch_%", "t"}}, + }, + }, + }, { Name: "Expressions without tables", Assertions: []ScriptTestAssertion{