cockroach
cockroach copied to clipboard
sql: support adding a column with a check constraint in same txn
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.
https://github.com/cockroachdb/cockroach/pull/34301