提交 56b472bd authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Document ALTER TABLE ALTER COLUMN DROP NOT NULL and remove incorrect information

上级 6c6fc7eb
...@@ -357,8 +357,8 @@ ALTER TABLE [ IF EXISTS ] tableName ALTER COLUMN columnName ...@@ -357,8 +357,8 @@ ALTER TABLE [ IF EXISTS ] tableName ALTER COLUMN columnName
| { SET DEFAULT expression } | { SET DEFAULT expression }
| { DROP DEFAULT } | { DROP DEFAULT }
| { SET ON UPDATE expression } | { SET ON UPDATE expression }
| { SET NULL }
| { SET NOT NULL } | { SET NOT NULL }
| { DROP NOT NULL } | { SET NULL }
| { SET { VISIBLE | INVISIBLE } } | { SET { VISIBLE | INVISIBLE } }
| { DROP ON UPDATE } } | { DROP ON UPDATE } }
"," ","
...@@ -382,11 +382,10 @@ DROP DEFAULT removes the default value of a column. ...@@ -382,11 +382,10 @@ DROP DEFAULT removes the default value of a column.
SET ON UPDATE changes the value that is set on update if value for this column is not specified in update statement. SET ON UPDATE changes the value that is set on update if value for this column is not specified in update statement.
SET NULL sets a column to allow NULL. The row may not be part of a primary key.
Single column indexes on this column are dropped.
SET NOT NULL sets a column to not allow NULL. Rows may not contains NULL in this column. SET NOT NULL sets a column to not allow NULL. Rows may not contains NULL in this column.
DROP NOT NULL and SET NULL set a column to allow NULL. The row may not be part of a primary key.
SET INVISIBLE makes the column hidden, i.e. it will not appear in SELECT * results. SET INVISIBLE makes the column hidden, i.e. it will not appear in SELECT * results.
SET VISIBLE has the reverse effect. SET VISIBLE has the reverse effect.
......
...@@ -63,9 +63,9 @@ public interface CommandInterface { ...@@ -63,9 +63,9 @@ public interface CommandInterface {
int ALTER_TABLE_ALTER_COLUMN_NOT_NULL = 8; int ALTER_TABLE_ALTER_COLUMN_NOT_NULL = 8;
/** /**
* The type of a ALTER TABLE ALTER COLUMN SET NULL statement. * The type of a ALTER TABLE ALTER COLUMN DROP NOT NULL statement.
*/ */
int ALTER_TABLE_ALTER_COLUMN_NULL = 9; int ALTER_TABLE_ALTER_COLUMN_DROP_NOT_NULL = 9;
/** /**
* The type of a ALTER TABLE ALTER COLUMN SET DEFAULT and ALTER TABLE ALTER * The type of a ALTER TABLE ALTER COLUMN SET DEFAULT and ALTER TABLE ALTER
......
...@@ -7216,7 +7216,7 @@ public class Parser { ...@@ -7216,7 +7216,7 @@ public class Parser {
Column column = columnIfTableExists(schema, tableName, columnName, ifTableExists); Column column = columnIfTableExists(schema, tableName, columnName, ifTableExists);
command.setOldColumn(column); command.setOldColumn(column);
if (nullConstraint == NullConstraintType.NULL_IS_ALLOWED) { if (nullConstraint == NullConstraintType.NULL_IS_ALLOWED) {
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL); command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_DROP_NOT_NULL);
} else { } else {
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL); command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL);
} }
...@@ -7273,7 +7273,7 @@ public class Parser { ...@@ -7273,7 +7273,7 @@ public class Parser {
command.setTableName(tableName); command.setTableName(tableName);
command.setIfTableExists(ifTableExists); command.setIfTableExists(ifTableExists);
command.setOldColumn(column); command.setOldColumn(column);
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL); command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_DROP_NOT_NULL);
return command; return command;
} else if (readIf("TYPE")) { } else if (readIf("TYPE")) {
// PostgreSQL compatibility // PostgreSQL compatibility
...@@ -7294,7 +7294,7 @@ public class Parser { ...@@ -7294,7 +7294,7 @@ public class Parser {
NullConstraintType nullConstraint = parseNotNullConstraint(); NullConstraintType nullConstraint = parseNotNullConstraint();
switch (nullConstraint) { switch (nullConstraint) {
case NULL_IS_ALLOWED: case NULL_IS_ALLOWED:
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL); command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_DROP_NOT_NULL);
break; break;
case NULL_IS_NOT_ALLOWED: case NULL_IS_NOT_ALLOWED:
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL); command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL);
......
...@@ -137,7 +137,7 @@ public class AlterTableAlterColumn extends CommandWithColumns { ...@@ -137,7 +137,7 @@ public class AlterTableAlterColumn extends CommandWithColumns {
db.updateMeta(session, table); db.updateMeta(session, table);
break; break;
} }
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL: { case CommandInterface.ALTER_TABLE_ALTER_COLUMN_DROP_NOT_NULL: {
if (oldColumn.isNullable()) { if (oldColumn.isNullable()) {
// no change // no change
break; break;
......
...@@ -23,5 +23,29 @@ ALTER TABLE TEST ALTER COLUMN T DROP DEFAULT; ...@@ -23,5 +23,29 @@ ALTER TABLE TEST ALTER COLUMN T DROP DEFAULT;
SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'T'; SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'T';
>> INT >> INT
-- SET NOT NULL
ALTER TABLE TEST ALTER COLUMN T SET NOT NULL;
> ok
SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'T';
>> INT NOT NULL
-- DROP NOT NULL
ALTER TABLE TEST ALTER COLUMN T DROP NOT NULL;
> ok
SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'T';
>> INT
ALTER TABLE TEST ALTER COLUMN T SET NOT NULL;
> ok
-- SET NULL
ALTER TABLE TEST ALTER COLUMN T SET NULL;
> ok
SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'T';
>> INT
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论