Skip to content

Commit 9b2c332

Browse files
committed
Merge branch 'fulghum/add_column_with_constraint' into fulghum-0e77d549
2 parents 4992fc3 + 1cab683 commit 9b2c332

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

enginetest/queries/alter_table_queries.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,22 @@ var AlterTableScripts = []ScriptTest{
513513
},
514514
},
515515
},
516+
{
517+
Name: "add column with inline check constraint definition",
518+
SetUpScript: []string{
519+
"create table t (pk int primary key);",
520+
},
521+
Assertions: []ScriptTestAssertion{
522+
{
523+
Query: "alter table t add column c int CONSTRAINT chk_c check(c > 10);",
524+
Expected: []sql.Row{{types.NewOkResult(0)}},
525+
},
526+
{
527+
Query: "insert into t values (1, 9);",
528+
ExpectedErrStr: `Check constraint "chk_c" violated`,
529+
},
530+
},
531+
},
516532
{
517533
Name: "multi-alter ddl column errors",
518534
SetUpScript: []string{

sql/planbuilder/ddl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ func (b *Builder) buildAlterTableClause(inScope *scope, ddl *ast.DDL) []*scope {
594594

595595
if ddl.ColumnAction != "" {
596596
columnActionOutscope := b.buildAlterTableColumnAction(tableScope, ddl, rt)
597-
outScopes = append(outScopes, columnActionOutscope)
597+
outScopes = append(outScopes, columnActionOutscope.copy())
598598

599599
if ddl.TableSpec != nil {
600600
if len(ddl.TableSpec.Columns) != 1 {

0 commit comments

Comments
 (0)