Skip to content

Commit

Permalink
Merge pull request #763 from dolthub/fulghum/column-default-exprs
Browse files Browse the repository at this point in the history
Wrap column default expressions in `ParenExpr`to match MySQL's requirements
  • Loading branch information
fulghum authored Sep 27, 2024
2 parents 5778da9 + 4d127aa commit 443b7f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/ast/column_table_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func nodeColumnTableDef(node *tree.ColumnTableDef) (_ *vitess.ColumnDefinition,
if err != nil {
return nil, err
}
// Wrap any default expression using a function call in parens to match MySQL's column default requirements
if _, ok := defaultExpr.(*vitess.FuncExpr); ok {
defaultExpr = &vitess.ParenExpr{Expr: defaultExpr}
}
if len(node.CheckExprs) > 0 {
return nil, fmt.Errorf("column-declared CHECK expressions are not yet supported")
}
Expand Down
18 changes: 18 additions & 0 deletions testing/go/create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,23 @@ func TestCreateTable(t *testing.T) {
},
},
},
{
Name: "Create table with column default expression using function",
Assertions: []ScriptTestAssertion{
{
// Test with a function in the column default expression
Query: "create table t1 (pk int primary key, c1 TEXT default length('Hello World!'));",
Expected: []sql.Row{},
},
{
Query: "insert into t1(pk) values (1);",
Expected: []sql.Row{},
},
{
Query: "select * from t1;",
Expected: []sql.Row{{1, "12"}},
},
},
},
})
}

0 comments on commit 443b7f0

Please sign in to comment.