tidb icon indicating copy to clipboard operation
tidb copied to clipboard

Support the definition of `null` change to `not null` using `alter table`

Open zimulala opened this issue 9 years ago • 3 comments

Refer to https://dev.mysql.com/doc/refman/5.7/en/alter-table.html.

zimulala avatar Nov 07 '17 02:11 zimulala

If we have no global lock on the table, it is not a trivial work.

winkyao avatar Apr 04 '18 07:04 winkyao

Relate to PR #6217 .

ciscoxll avatar Apr 04 '18 07:04 ciscoxll

I have verified two test cases, behavior is the same as MySQL:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a int not null primary key auto_increment, b INT NULL);
INSERT INTO t1 (b) VALUES (1);
ALTER TABLE t1 CHANGE b b INT NOT NULL;

And an error:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a int not null primary key auto_increment, b INT NULL);
INSERT INTO t1 (b) VALUES (NULL);
ALTER TABLE t1 CHANGE b b INT NOT NULL;

# Result:
ERROR 1138 (22004): Invalid use of NULL value

I am going to close this task now.

morgo avatar Mar 21 '19 21:03 morgo