提交 9cbb5a2d authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved PostgreSQL compatibility for ALTER TABLE ALTER COLUMN.

上级 9a423776
...@@ -4451,18 +4451,32 @@ public class Parser { ...@@ -4451,18 +4451,32 @@ public class Parser {
String newName = readColumnIdentifier(); String newName = readColumnIdentifier();
command.setNewColumnName(newName); command.setNewColumnName(newName);
return command; return command;
} else if (readIf("SET")) { } else if (readIf("DROP")) {
if (readIf("DATA")) { // PostgreSQL compatibility
// Derby compatibility if (readIf("DEFAULT")) {
read("TYPE");
Column newColumn = parseColumnForTable(columnName, column.isNullable());
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema()); AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table); command.setTable(table);
command.setType(AlterTableAlterColumn.CHANGE_TYPE);
command.setOldColumn(column); command.setOldColumn(column);
command.setNewColumn(newColumn); command.setType(AlterTableAlterColumn.DEFAULT);
command.setDefaultExpression(null);
return command; return command;
} }
read("NOT");
read("NULL");
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table);
command.setOldColumn(column);
command.setType(AlterTableAlterColumn.NULL);
return command;
} else if (readIf("TYPE")) {
// PostgreSQL compatibility
return parseAlterTableAlterColumnType(table, columnName, column);
} else if (readIf("SET")) {
if (readIf("DATA")) {
// Derby compatibility
read("TYPE");
return parseAlterTableAlterColumnType(table, columnName, column);
}
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema()); AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table); command.setTable(table);
command.setOldColumn(column); command.setOldColumn(column);
...@@ -4494,6 +4508,13 @@ public class Parser { ...@@ -4494,6 +4508,13 @@ public class Parser {
command.setSelectivity(readExpression()); command.setSelectivity(readExpression());
return command; return command;
} else { } else {
return parseAlterTableAlterColumnType(table, columnName, column);
}
}
throw getSyntaxError();
}
private AlterTableAlterColumn parseAlterTableAlterColumnType(Table table, String columnName, Column column) {
Column newColumn = parseColumnForTable(columnName, column.isNullable()); Column newColumn = parseColumnForTable(columnName, column.isNullable());
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema()); AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table); command.setTable(table);
...@@ -4502,9 +4523,6 @@ public class Parser { ...@@ -4502,9 +4523,6 @@ public class Parser {
command.setNewColumn(newColumn); command.setNewColumn(newColumn);
return command; return command;
} }
}
throw getSyntaxError();
}
private AlterTableAlterColumn parseAlterTableAddColumn(Table table) { private AlterTableAlterColumn parseAlterTableAddColumn(Table table) {
readIf("COLUMN"); readIf("COLUMN");
......
create table test(id int);
alter table test alter column id set default 'x';
select column_default from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
> 'x';
alter table test alter column id set not null;
select is_nullable from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
> NO;
alter table test alter column id set data type varchar;
select type_name from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
> VARCHAR;
alter table test alter column id type int;
select type_name from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
> INTEGER;
alter table test alter column id drop default;
select column_default from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
> null;
alter table test alter column id drop not null;
select is_nullable from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
> YES;
drop table test;
select cast(cast(0.1 as real) as decimal); select cast(cast(0.1 as real) as decimal);
> 0.1; > 0.1;
select cast(cast(95605327.73 as float) as decimal); select cast(cast(95605327.73 as float) as decimal);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论