Unverified 提交 3617e3f7 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #948 from katzyn/ddl

Fix some grammar descriptions and ALTER TABLE DROP COLUMN parsing
...@@ -227,9 +227,8 @@ SHOW TABLES ...@@ -227,9 +227,8 @@ SHOW TABLES
" "
"Commands (DML)","WITH"," "Commands (DML)","WITH","
WITH [ RECURSIVE ] { name [( columnName [,...] )] WITH [ RECURSIVE ] { name [( columnName [,...] )] AS ( select ) [,...] }
AS ( select ) [,...] } { select | insert | update | merge | delete | createTable }
{ select | insert | update | merge | delete | createTable }
"," ","
Can be used to create a recursive or non-recursive query (common table expression). Can be used to create a recursive or non-recursive query (common table expression).
For recursive queries the first select has to be a UNION. For recursive queries the first select has to be a UNION.
...@@ -373,13 +372,14 @@ ALTER TABLE TEST ALTER COLUMN NAME SET INVISIBLE; ...@@ -373,13 +372,14 @@ ALTER TABLE TEST ALTER COLUMN NAME SET INVISIBLE;
"Commands (DDL)","ALTER TABLE DROP COLUMN"," "Commands (DDL)","ALTER TABLE DROP COLUMN","
ALTER TABLE [ IF EXISTS ] tableName DROP COLUMN [ IF EXISTS ] ALTER TABLE [ IF EXISTS ] tableName DROP COLUMN [ IF EXISTS ]
( columnName [,...] ) columnName [,...] | ( columnName [,...] )
"," ","
Removes column(s) from a table. Removes column(s) from a table.
This command commits an open transaction in this connection. This command commits an open transaction in this connection.
"," ","
ALTER TABLE TEST DROP COLUMN NAME ALTER TABLE TEST DROP COLUMN NAME
ALTER TABLE TEST DROP COLUMN NAME1, NAME2 ALTER TABLE TEST DROP COLUMN NAME1, NAME2
ALTER TABLE TEST DROP COLUMN (NAME1, NAME2)
" "
"Commands (DDL)","ALTER TABLE DROP CONSTRAINT"," "Commands (DDL)","ALTER TABLE DROP CONSTRAINT","
...@@ -394,7 +394,7 @@ ALTER TABLE TEST DROP CONSTRAINT UNIQUE_NAME ...@@ -394,7 +394,7 @@ ALTER TABLE TEST DROP CONSTRAINT UNIQUE_NAME
"Commands (DDL)","ALTER TABLE SET"," "Commands (DDL)","ALTER TABLE SET","
ALTER TABLE [ IF EXISTS ] tableName SET REFERENTIAL_INTEGRITY ALTER TABLE [ IF EXISTS ] tableName SET REFERENTIAL_INTEGRITY
{ FALSE | TRUE [ CHECK | NOCHECK ] } { FALSE | TRUE } [ CHECK | NOCHECK ]
"," ","
Disables or enables referential integrity checking for a table. This command can Disables or enables referential integrity checking for a table. This command can
be used inside a transaction. Enabling referential integrity does not check be used inside a transaction. Enabling referential integrity does not check
......
...@@ -6103,28 +6103,28 @@ public class Parser { ...@@ -6103,28 +6103,28 @@ public class Parser {
} else { } else {
readIf("COLUMN"); readIf("COLUMN");
boolean ifExists = readIfExists(false); boolean ifExists = readIfExists(false);
AlterTableAlterColumn command = new AlterTableAlterColumn(
session, schema);
command.setType(CommandInterface.ALTER_TABLE_DROP_COLUMN);
ArrayList<Column> columnsToRemove = New.arrayList(); ArrayList<Column> columnsToRemove = New.arrayList();
Table table = tableIfTableExists(schema, tableName, ifTableExists); Table table = tableIfTableExists(schema, tableName, ifTableExists);
// For Oracle compatibility - open bracket required // For Oracle compatibility - open bracket required
boolean openingBracketDetected = readIf("("); boolean openingBracketDetected = readIf("(");
do { do {
String columnName = readColumnIdentifier(); String columnName = readColumnIdentifier();
if (table == null) { if (table != null) {
return new NoOperation(session); if (!ifExists || table.doesColumnExist(columnName)) {
}
if (ifExists && !table.doesColumnExist(columnName)) {
return new NoOperation(session);
}
Column column = table.getColumn(columnName); Column column = table.getColumn(columnName);
columnsToRemove.add(column); columnsToRemove.add(column);
}
}
} while (readIf(",")); } while (readIf(","));
if (openingBracketDetected) { if (openingBracketDetected) {
// For Oracle compatibility - close bracket // For Oracle compatibility - close bracket
read(")"); read(")");
} }
if (table == null || columnsToRemove.isEmpty()) {
return new NoOperation(session);
}
AlterTableAlterColumn command = new AlterTableAlterColumn(session, schema);
command.setType(CommandInterface.ALTER_TABLE_DROP_COLUMN);
command.setTableName(tableName); command.setTableName(tableName);
command.setIfTableExists(ifTableExists); command.setIfTableExists(ifTableExists);
command.setColumnsToRemove(columnsToRemove); command.setColumnsToRemove(columnsToRemove);
......
...@@ -101,7 +101,7 @@ public class TestScript extends TestBase { ...@@ -101,7 +101,7 @@ public class TestScript extends TestBase {
"uuid", "varchar", "varchar-ignorecase" }) { "uuid", "varchar", "varchar-ignorecase" }) {
testScript("datatypes/" + s + ".sql"); testScript("datatypes/" + s + ".sql");
} }
for (String s : new String[] { "alterTableAdd", "createView", "dropSchema" }) { for (String s : new String[] { "alterTableAdd", "alterTableDropColumn", "createView", "dropSchema" }) {
testScript("ddl/" + s + ".sql"); testScript("ddl/" + s + ".sql");
} }
for (String s : new String[] { "insertIgnore", "mergeUsing", "script", "with" }) { for (String s : new String[] { "insertIgnore", "mergeUsing", "script", "with" }) {
......
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE TABLE TEST(A VARCHAR, B VARCHAR, C VARCHAR AS LOWER(A));
> ok
ALTER TABLE TEST DROP COLUMN B;
> ok
DROP TABLE TEST;
> ok
ALTER TABLE IF EXISTS TEST DROP COLUMN A;
> ok
ALTER TABLE TEST DROP COLUMN A;
> exception
CREATE TABLE TEST(A INT, B INT, C INT, D INT, E INT, F INT, G INT, H INT, I INT, J INT);
> ok
ALTER TABLE TEST DROP COLUMN IF EXISTS J;
> ok
ALTER TABLE TEST DROP COLUMN J;
> exception
ALTER TABLE TEST DROP COLUMN B;
> ok
ALTER TABLE TEST DROP COLUMN IF EXISTS C;
> ok
SELECT * FROM TEST;
> A D E F G H I
> - - - - - - -
> rows: 0
ALTER TABLE TEST DROP COLUMN B, D;
> exception
ALTER TABLE TEST DROP COLUMN IF EXISTS B, D;
> ok
SELECT * FROM TEST;
> A E F G H I
> - - - - - -
> rows: 0
ALTER TABLE TEST DROP COLUMN E, F;
> ok
SELECT * FROM TEST;
> A G H I
> - - - -
> rows: 0
ALTER TABLE TEST DROP COLUMN (B, H);
> exception
ALTER TABLE TEST DROP COLUMN IF EXISTS (B, H);
> ok
SELECT * FROM TEST;
> A G I
> - - -
> rows: 0
ALTER TABLE TEST DROP COLUMN (G, I);
> ok
SELECT * FROM TEST;
> A
> -
> rows: 0
DROP TABLE TEST;
> ok
...@@ -2241,15 +2241,6 @@ select * from (select 1), (select 2); ...@@ -2241,15 +2241,6 @@ select * from (select 1), (select 2);
> 1 2 > 1 2
> rows: 1 > rows: 1
CREATE TABLE TEST(A VARCHAR, B VARCHAR, C VARCHAR AS LOWER(A));
> ok
ALTER TABLE TEST DROP COLUMN B;
> ok
DROP TABLE TEST;
> ok
create table t1(c1 int, c2 int); create table t1(c1 int, c2 int);
> ok > ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论