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
"
"Commands (DML)","WITH","
WITH [ RECURSIVE ] { name [( columnName [,...] )]
AS ( select ) [,...] }
{ select | insert | update | merge | delete | createTable }
WITH [ RECURSIVE ] { name [( columnName [,...] )] AS ( select ) [,...] }
{ select | insert | update | merge | delete | createTable }
","
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.
......@@ -373,13 +372,14 @@ ALTER TABLE TEST ALTER COLUMN NAME SET INVISIBLE;
"Commands (DDL)","ALTER TABLE DROP COLUMN","
ALTER TABLE [ IF EXISTS ] tableName DROP COLUMN [ IF EXISTS ]
( columnName [,...] )
columnName [,...] | ( columnName [,...] )
","
Removes column(s) from a table.
This command commits an open transaction in this connection.
","
ALTER TABLE TEST DROP COLUMN NAME
ALTER TABLE TEST DROP COLUMN NAME1, NAME2
ALTER TABLE TEST DROP COLUMN (NAME1, NAME2)
"
"Commands (DDL)","ALTER TABLE DROP CONSTRAINT","
......@@ -394,7 +394,7 @@ ALTER TABLE TEST DROP CONSTRAINT UNIQUE_NAME
"Commands (DDL)","ALTER TABLE SET","
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
be used inside a transaction. Enabling referential integrity does not check
......
......@@ -6103,28 +6103,28 @@ public class Parser {
} else {
readIf("COLUMN");
boolean ifExists = readIfExists(false);
AlterTableAlterColumn command = new AlterTableAlterColumn(
session, schema);
command.setType(CommandInterface.ALTER_TABLE_DROP_COLUMN);
ArrayList<Column> columnsToRemove = New.arrayList();
Table table = tableIfTableExists(schema, tableName, ifTableExists);
// For Oracle compatibility - open bracket required
boolean openingBracketDetected = readIf("(");
do {
String columnName = readColumnIdentifier();
if (table == null) {
return new NoOperation(session);
}
if (ifExists && !table.doesColumnExist(columnName)) {
return new NoOperation(session);
if (table != null) {
if (!ifExists || table.doesColumnExist(columnName)) {
Column column = table.getColumn(columnName);
columnsToRemove.add(column);
}
}
Column column = table.getColumn(columnName);
columnsToRemove.add(column);
} while (readIf(","));
if (openingBracketDetected) {
// For Oracle compatibility - close bracket
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.setIfTableExists(ifTableExists);
command.setColumnsToRemove(columnsToRemove);
......
......@@ -101,7 +101,7 @@ public class TestScript extends TestBase {
"uuid", "varchar", "varchar-ignorecase" }) {
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");
}
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);
> 1 2
> 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);
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论