Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions server/analyzer/assign_insert_casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions testing/go/prepared_statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading