Skip to content

Commit a347788

Browse files
committed
Adding a test for #1359
1 parent daf377e commit a347788

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

testing/go/alter_table_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,27 @@ func TestAlterTable(t *testing.T) {
327327
},
328328
},
329329
},
330+
{
331+
Name: "Add column with inline check constraint to table with existing data",
332+
SetUpScript: []string{
333+
"CREATE TABLE test1 (a INT, b INT);",
334+
"INSERT INTO test1 VALUES (1, 1);",
335+
},
336+
Assertions: []ScriptTestAssertion{
337+
{
338+
Query: "ALTER TABLE test1 ADD COLUMN c INT NOT NULL DEFAULT 42 CONSTRAINT chk1 CHECK (c > 0);",
339+
Expected: []sql.Row{},
340+
},
341+
{
342+
Query: "INSERT INTO test1 VALUES (2, 2, -2);",
343+
ExpectedErr: `Check constraint "chk1" violated`,
344+
},
345+
{
346+
Query: "ALTER TABLE test1 ADD COLUMN c2 INT CONSTRAINT chk2 CHECK (c2 IS NOT NULL);",
347+
ExpectedErr: `Check constraint "chk2" violated`,
348+
},
349+
},
350+
},
330351
{
331352
Name: "Drop Column",
332353
SetUpScript: []string{

0 commit comments

Comments
 (0)