cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: support adding a column with a check constraint in same txn

Open thoszhang opened this issue 7 years ago • 1 comments

Currently, adding a column and adding a check constraint on that column within the same transaction is not supported:

[email protected]:60903/defaultdb> BEGIN;
                             -> ALTER TABLE t ADD COLUMN b INT DEFAULT (INT '0');
                             -> ALTER TABLE t ADD CONSTRAINT c CHECK (b > 0);
                             -> COMMIT;
pq: column "b" not found for constraint "b"

We should support adding a constraint on the column that's being added. Additionally, we should validate the new constraint on the new column's default values, if applicable (as in the example above), and fail the transaction if validation fails.

This issue is being filed to track progress on #32504 (see the new logic tests for more examples). #33550 is a related issue.

thoszhang avatar Jan 09 '19 17:01 thoszhang

https://github.com/cockroachdb/cockroach/pull/34301

vivekmenezes avatar Feb 13 '19 17:02 vivekmenezes