Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b0b3c31b
提交
b0b3c31b
authored
1月 18, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ALTER TABLE ALTER COLUMN SET DATA TYPE is a standard syntax
上级
56b472bd
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
67 行增加
和
9 行删除
+67
-9
help.csv
h2/src/docsrc/help/help.csv
+3
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+45
-9
alterTableAlterColumn.sql
...rc/test/org/h2/test/scripts/ddl/alterTableAlterColumn.sql
+19
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
b0b3c31b
...
...
@@ -359,6 +359,7 @@ ALTER TABLE [ IF EXISTS ] tableName ALTER COLUMN columnName
| { SET ON UPDATE expression }
| { SET NOT NULL }
| { DROP NOT NULL } | { SET NULL }
| { SET DATA TYPE dataType }
| { SET { VISIBLE | INVISIBLE } }
| { DROP ON UPDATE } }
","
...
...
@@ -386,6 +387,8 @@ SET NOT NULL sets a column to not allow NULL. Rows may not contains NULL in this
DROP NOT NULL and SET NULL set a column to allow NULL. The row may not be part of a primary key.
SET DATA TYPE changes the data type of a column.
SET INVISIBLE makes the column hidden, i.e. it will not appear in SELECT * results.
SET VISIBLE has the reverse effect.
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
b0b3c31b
...
...
@@ -7277,14 +7277,11 @@ public class Parser {
return
command
;
}
else
if
(
readIf
(
"TYPE"
))
{
// PostgreSQL compatibility
return
parseAlterTableAlterColumnType
(
schema
,
tableName
,
columnName
,
ifTableExists
);
return
parseAlterTableAlterColumnDataType
(
schema
,
tableName
,
columnName
,
ifTableExists
);
}
else
if
(
readIf
(
"SET"
))
{
if
(
readIf
(
"DATA"
))
{
// Derby compatibility
read
(
"TYPE"
);
return
parseAlterTableAlterColumnType
(
schema
,
tableName
,
columnName
,
ifTableExists
);
return
parseAlterTableAlterColumnDataType
(
schema
,
tableName
,
columnName
,
ifTableExists
);
}
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
session
,
schema
);
...
...
@@ -7341,8 +7338,7 @@ public class Parser {
command
.
setSelectivity
(
readExpression
());
return
command
;
}
else
{
return
parseAlterTableAlterColumnType
(
schema
,
tableName
,
columnName
,
ifTableExists
);
return
parseAlterTableAlterColumnType
(
schema
,
tableName
,
columnName
,
ifTableExists
);
}
}
throw
getSyntaxError
();
...
...
@@ -7374,8 +7370,48 @@ public class Parser {
Column
oldColumn
=
columnIfTableExists
(
schema
,
tableName
,
columnName
,
ifTableExists
);
Column
newColumn
=
parseColumnForTable
(
columnName
,
oldColumn
==
null
?
true
:
oldColumn
.
isNullable
(),
true
);
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
session
,
schema
);
if
(
readIf
(
CHECK
))
{
Expression
expr
=
readExpression
();
newColumn
.
addCheckConstraint
(
session
,
expr
);
}
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
session
,
schema
);
command
.
setTableName
(
tableName
);
command
.
setIfTableExists
(
ifTableExists
);
command
.
setType
(
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE
);
command
.
setOldColumn
(
oldColumn
);
command
.
setNewColumn
(
newColumn
);
return
command
;
}
private
AlterTableAlterColumn
parseAlterTableAlterColumnDataType
(
Schema
schema
,
String
tableName
,
String
columnName
,
boolean
ifTableExists
)
{
Column
oldColumn
=
columnIfTableExists
(
schema
,
tableName
,
columnName
,
ifTableExists
);
Column
newColumn
=
parseColumnWithType
(
columnName
,
true
);
if
(
oldColumn
!=
null
)
{
if
(!
oldColumn
.
isNullable
())
{
newColumn
.
setNullable
(
false
);
}
if
(!
oldColumn
.
getVisible
())
{
newColumn
.
setVisible
(
false
);
}
Expression
e
=
oldColumn
.
getDefaultExpression
();
if
(
e
!=
null
)
{
newColumn
.
setDefaultExpression
(
session
,
e
);
}
e
=
oldColumn
.
getOnUpdateExpression
();
if
(
e
!=
null
)
{
newColumn
.
setOnUpdateExpression
(
session
,
e
);
}
e
=
oldColumn
.
getCheckConstraint
(
session
,
columnName
);
if
(
e
!=
null
)
{
newColumn
.
addCheckConstraint
(
session
,
e
);
}
String
c
=
oldColumn
.
getComment
();
if
(
c
!=
null
)
{
newColumn
.
setComment
(
c
);
}
}
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
session
,
schema
);
command
.
setTableName
(
tableName
);
command
.
setIfTableExists
(
ifTableExists
);
command
.
setType
(
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE
);
...
...
h2/src/test/org/h2/test/scripts/ddl/alterTableAlterColumn.sql
浏览文件 @
b0b3c31b
...
...
@@ -47,5 +47,24 @@ ALTER TABLE TEST ALTER COLUMN T SET NULL;
SELECT
COLUMN_TYPE
FROM
INFORMATION_SCHEMA
.
COLUMNS
WHERE
COLUMN_NAME
=
'T'
;
>>
INT
-- SET DATA TYPE
ALTER
TABLE
TEST
ALTER
COLUMN
T
SET
DATA
TYPE
BIGINT
;
>
ok
SELECT
COLUMN_TYPE
FROM
INFORMATION_SCHEMA
.
COLUMNS
WHERE
COLUMN_NAME
=
'T'
;
>>
BIGINT
ALTER
TABLE
TEST
ALTER
COLUMN
T
INT
INVISIBLE
DEFAULT
1
ON
UPDATE
2
NOT
NULL
COMMENT
'C'
CHECK
T
<
100
;
>
ok
SELECT
COLUMN_TYPE
FROM
INFORMATION_SCHEMA
.
COLUMNS
WHERE
COLUMN_NAME
=
'T'
;
>>
INT
INVISIBLE
DEFAULT
1
ON
UPDATE
2
NOT
NULL
COMMENT
'C'
CHECK
(
T
<
100
)
ALTER
TABLE
TEST
ALTER
COLUMN
T
SET
DATA
TYPE
BIGINT
;
>
ok
SELECT
COLUMN_TYPE
FROM
INFORMATION_SCHEMA
.
COLUMNS
WHERE
COLUMN_NAME
=
'T'
;
>>
BIGINT
INVISIBLE
DEFAULT
1
ON
UPDATE
2
NOT
NULL
COMMENT
'C'
CHECK
(
T
<
100
)
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论