Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
9cbb5a2d
提交
9cbb5a2d
authored
15 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved PostgreSQL compatibility for ALTER TABLE ALTER COLUMN.
上级
9a423776
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
52 行增加
和
14 行删除
+52
-14
Parser.java
h2/src/main/org/h2/command/Parser.java
+32
-14
testSimple.in.txt
h2/src/test/org/h2/test/testSimple.in.txt
+20
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
9cbb5a2d
...
...
@@ -4451,18 +4451,32 @@ public class Parser {
String
newName
=
readColumnIdentifier
();
command
.
setNewColumnName
(
newName
);
return
command
;
}
else
if
(
readIf
(
"SET"
))
{
if
(
readIf
(
"DATA"
))
{
// Derby compatibility
read
(
"TYPE"
);
Column
newColumn
=
parseColumnForTable
(
columnName
,
column
.
isNullable
());
}
else
if
(
readIf
(
"DROP"
))
{
// PostgreSQL compatibility
if
(
readIf
(
"DEFAULT"
))
{
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
session
,
table
.
getSchema
());
command
.
setTable
(
table
);
command
.
setType
(
AlterTableAlterColumn
.
CHANGE_TYPE
);
command
.
setOldColumn
(
column
);
command
.
setNewColumn
(
newColumn
);
command
.
setType
(
AlterTableAlterColumn
.
DEFAULT
);
command
.
setDefaultExpression
(
null
);
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
());
command
.
setTable
(
table
);
command
.
setOldColumn
(
column
);
...
...
@@ -4494,18 +4508,22 @@ public class Parser {
command
.
setSelectivity
(
readExpression
());
return
command
;
}
else
{
Column
newColumn
=
parseColumnForTable
(
columnName
,
column
.
isNullable
());
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
session
,
table
.
getSchema
());
command
.
setTable
(
table
);
command
.
setType
(
AlterTableAlterColumn
.
CHANGE_TYPE
);
command
.
setOldColumn
(
column
);
command
.
setNewColumn
(
newColumn
);
return
command
;
return
parseAlterTableAlterColumnType
(
table
,
columnName
,
column
);
}
}
throw
getSyntaxError
();
}
private
AlterTableAlterColumn
parseAlterTableAlterColumnType
(
Table
table
,
String
columnName
,
Column
column
)
{
Column
newColumn
=
parseColumnForTable
(
columnName
,
column
.
isNullable
());
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
session
,
table
.
getSchema
());
command
.
setTable
(
table
);
command
.
setType
(
AlterTableAlterColumn
.
CHANGE_TYPE
);
command
.
setOldColumn
(
column
);
command
.
setNewColumn
(
newColumn
);
return
command
;
}
private
AlterTableAlterColumn
parseAlterTableAddColumn
(
Table
table
)
{
readIf
(
"COLUMN"
);
Schema
schema
=
table
.
getSchema
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/testSimple.in.txt
浏览文件 @
9cbb5a2d
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);
> 0.1;
select cast(cast(95605327.73 as float) as decimal);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论