提交 f249c20b authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add support for SQL:2003 WITH [NO] DATA to CREATE TABLE AS

上级 a778d6ee
......@@ -708,7 +708,7 @@ TABLE [ IF NOT EXISTS ] name
[ ENGINE tableEngineName ]
[ WITH tableEngineParamName [,...] ]
[ NOT PERSISTENT ] [ TRANSACTIONAL ]
[ AS select ]","
[ AS select [ WITH [ NO ] DATA ] ]","
Creates a new table.
Cached tables (the default for regular tables) are persistent,
......@@ -736,6 +736,7 @@ rows are lost when the database is closed.
The column definition is 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.
This command commits an open transaction, except when using
TRANSACTIONAL (only supported for temporary tables).
......
......@@ -6679,6 +6679,10 @@ public class Parser {
command.setSortedInsertMode(true);
}
command.setQuery(parseSelect());
if (readIf("WITH")) {
command.setWithNoData(readIf("NO"));
read("DATA");
}
}
// for MySQL compatibility
if (readIf("ROW_FORMAT")) {
......
......@@ -38,6 +38,7 @@ public class CreateTable extends CommandWithColumns {
private Query asQuery;
private String comment;
private boolean sortedInsertMode;
private boolean withNoData;
public CreateTable(Session session, Schema schema) {
super(session, schema);
......@@ -120,7 +121,7 @@ public class CreateTable extends CommandWithColumns {
table.addSequence(sequence);
}
createConstraints();
if (asQuery != null) {
if (asQuery != null && !withNoData) {
boolean old = session.isUndoLogEnabled();
try {
session.setUndoLogEnabled(false);
......@@ -245,6 +246,10 @@ public class CreateTable extends CommandWithColumns {
this.sortedInsertMode = sortedInsertMode;
}
public void setWithNoData(boolean withNoData) {
this.withNoData = withNoData;
}
public void setTableEngine(String tableEngine) {
data.tableEngine = tableEngine;
}
......
......@@ -14,3 +14,49 @@ SELECT CONSTRAINT_NAME, CONSTRAINT_TYPE FROM INFORMATION_SCHEMA.TABLE_CONSTRAINT
DROP TABLE TEST;
> ok
CREATE TABLE T1(ID INT PRIMARY KEY, COL2 INT);
> ok
INSERT INTO T1 VALUES (1, 2), (11, 22);
> update count: 2
CREATE TABLE T2 AS SELECT * FROM T1;
> ok
SELECT * FROM T2 ORDER BY ID;
> ID COL2
> -- ----
> 1 2
> 11 22
> rows (ordered): 2
DROP TABLE T2;
> ok
CREATE TABLE T2 AS SELECT * FROM T1 WITH DATA;
> ok
SELECT * FROM T2 ORDER BY ID;
> ID COL2
> -- ----
> 1 2
> 11 22
> rows (ordered): 2
DROP TABLE T2;
> ok
CREATE TABLE T2 AS SELECT * FROM T1 WITH NO DATA;
> ok
SELECT * FROM T2 ORDER BY ID;
> ID COL2
> -- ----
> rows (ordered): 0
DROP TABLE T2;
> ok
DROP TABLE T1;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论