Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
fabf9b36
提交
fabf9b36
authored
1月 31, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for standard syntax of CREATE TABLE AS query
上级
b322526e
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
40 行增加
和
8 行删除
+40
-8
help.csv
h2/src/docsrc/help/help.csv
+2
-2
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+10
-6
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+9
-0
createTable.sql
h2/src/test/org/h2/test/scripts/ddl/createTable.sql
+17
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
fabf9b36
...
...
@@ -739,7 +739,7 @@ CREATE SEQUENCE SEQ_ID
"Commands (DDL)","CREATE TABLE","
CREATE [ CACHED | MEMORY ] [ TEMP | [ GLOBAL | LOCAL ] TEMPORARY ]
TABLE [ IF NOT EXISTS ] name
[ ( { columnName
columnDefinition
| constraint } [,...] ) ]
[ ( { columnName
[columnDefinition]
| constraint } [,...] ) ]
[ ENGINE tableEngineName ]
[ WITH tableEngineParamName [,...] ]
[ NOT PERSISTENT ] [ TRANSACTIONAL ]
...
...
@@ -769,7 +769,7 @@ in CREATE TABLE, then the engine specified by DEFAULT_TABLE_ENGINE option of dat
Tables with the NOT PERSISTENT modifier are kept fully in memory, and all
rows are lost when the database is closed.
The column definition
is
optional if a query is specified.
The column definition
s are
optional if a query is specified.
In that case the column list of the query is used.
If the query is specified its results are inserted into created table unless WITH NO DATA is specified.
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
fabf9b36
...
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue #1708: CREATE TABLE AS doesn't support column lists without data types
</li>
<li>
PR #1707: Fix sort order and ENUM data type in external results
</li>
<li>
PR #1706: Add hypothetical set functions
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
fabf9b36
...
...
@@ -7466,12 +7466,12 @@ public class Parser {
if
(
readIf
(
OPEN_PAREN
))
{
command
.
setIfNotExists
(
false
);
do
{
parseTableColumnDefinition
(
command
,
schema
,
tableName
);
parseTableColumnDefinition
(
command
,
schema
,
tableName
,
false
);
}
while
(
readIfMore
(
true
));
}
else
{
boolean
ifNotExists
=
readIfNotExists
();
command
.
setIfNotExists
(
ifNotExists
);
parseTableColumnDefinition
(
command
,
schema
,
tableName
);
parseTableColumnDefinition
(
command
,
schema
,
tableName
,
false
);
}
if
(
readIf
(
"BEFORE"
))
{
command
.
setAddBefore
(
readColumnIdentifier
());
...
...
@@ -7717,7 +7717,7 @@ public class Parser {
if
(
readIf
(
OPEN_PAREN
))
{
if
(!
readIf
(
CLOSE_PAREN
))
{
do
{
parseTableColumnDefinition
(
command
,
schema
,
tableName
);
parseTableColumnDefinition
(
command
,
schema
,
tableName
,
true
);
}
while
(
readIfMore
(
false
));
}
}
...
...
@@ -7806,13 +7806,17 @@ public class Parser {
return
command
;
}
private
void
parseTableColumnDefinition
(
CommandWithColumns
command
,
Schema
schema
,
String
tableName
)
{
DefineCommand
c
=
parseAlterTableAddConstraintIf
(
tableName
,
schema
,
false
);
private
void
parseTableColumnDefinition
(
CommandWithColumns
command
,
Schema
schema
,
String
tableName
,
boolean
forCreateTable
)
{
DefineCommand
c
=
parseAlterTableAddConstraintIf
(
tableName
,
schema
,
false
);
if
(
c
!=
null
)
{
command
.
addConstraintCommand
(
c
);
}
else
{
String
columnName
=
readColumnIdentifier
();
if
(
forCreateTable
&&
(
currentTokenType
==
COMMA
||
currentTokenType
==
CLOSE_PAREN
))
{
command
.
addColumn
(
new
Column
(
columnName
,
TypeInfo
.
TYPE_UNKNOWN
));
return
;
}
Column
column
=
parseColumnForTable
(
columnName
,
true
,
true
);
if
(
column
.
isAutoIncrement
()
&&
column
.
isPrimaryKey
())
{
column
.
setPrimaryKey
(
false
);
...
...
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
fabf9b36
...
...
@@ -21,6 +21,7 @@ import org.h2.schema.Sequence;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.util.ColumnNamer
;
import
org.h2.value.Value
;
/**
* This class represents the statement
...
...
@@ -89,6 +90,14 @@ public class CreateTable extends CommandWithColumns {
generateColumnsFromQuery
();
}
else
if
(
data
.
columns
.
size
()
!=
asQuery
.
getColumnCount
())
{
throw
DbException
.
get
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
);
}
else
{
ArrayList
<
Column
>
columns
=
data
.
columns
;
for
(
int
i
=
0
;
i
<
columns
.
size
();
i
++)
{
Column
column
=
columns
.
get
(
i
);
if
(
column
.
getType
().
getValueType
()
==
Value
.
UNKNOWN
)
{
columns
.
set
(
i
,
new
Column
(
column
.
getName
(),
asQuery
.
getExpressions
().
get
(
i
).
getType
()));
}
}
}
}
changePrimaryKeysToNotNull
(
data
.
columns
);
...
...
h2/src/test/org/h2/test/scripts/ddl/createTable.sql
浏览文件 @
fabf9b36
...
...
@@ -114,3 +114,20 @@ SELECT CONSTRAINT_TYPE, TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHE
DROP
TABLE
TEST1
,
TEST2
,
TEST3
;
>
ok
CREATE
TABLE
TEST
(
A
);
>
exception
UNKNOWN_DATA_TYPE_1
CREATE
TABLE
TEST
(
A
,
B
,
C
)
AS
SELECT
1
,
2
,
CAST
(
'A'
AS
VARCHAR
);
>
ok
SELECT
COLUMN_NAME
,
COLUMN_TYPE
FROM
INFORMATION_SCHEMA
.
COLUMNS
WHERE
TABLE_NAME
=
'TEST'
;
>
COLUMN_NAME
COLUMN_TYPE
>
----------- -----------
>
A
INTEGER
>
B
INTEGER
>
C
VARCHAR
>
rows
:
3
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论