Skip to content

Commit

Permalink
support rename table without keyword TABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
lingtaolf committed Oct 9, 2023
1 parent 55fc3fe commit 60fe7c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Parsers/ParserRenameQuery.cpp
Expand Up @@ -11,6 +11,7 @@ namespace DB

bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
ParserKeyword s_rename("RENAME");
ParserKeyword s_rename_table("RENAME TABLE");
ParserKeyword s_exchange_tables("EXCHANGE TABLES");
ParserKeyword s_rename_dictionary("RENAME DICTIONARY");
Expand All @@ -24,18 +25,7 @@ bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
bool exchange = false;
bool dictionary = false;

if (s_rename_table.ignore(pos, expected))
;
else if (s_exchange_tables.ignore(pos, expected))
exchange = true;
else if (s_rename_dictionary.ignore(pos, expected))
dictionary = true;
else if (s_exchange_dictionaries.ignore(pos, expected))
{
exchange = true;
dictionary = true;
}
else if (s_rename_database.ignore(pos, expected))
if (s_rename_database.ignore(pos, expected))
{
ASTPtr from_db;
ASTPtr to_db;
Expand Down Expand Up @@ -67,6 +57,19 @@ bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
node = query;
return true;
}
else if(s_rename_table.ignore(pos, expected))
;
else if (s_rename.ignore(pos, expected))
;
else if (s_exchange_tables.ignore(pos, expected))
exchange = true;
else if (s_rename_dictionary.ignore(pos, expected))
dictionary = true;
else if (s_exchange_dictionaries.ignore(pos, expected))
{
exchange = true;
dictionary = true;
}
else
return false;

Expand Down
@@ -0,0 +1,3 @@
r1
r2
r3
14 changes: 14 additions & 0 deletions tests/queries/0_stateless/02891_rename_table_without_keyword.sql
@@ -0,0 +1,14 @@
DROP DATABASE IF EXISTS rename_db;
CREATE DATABASE rename_db;

CREATE TABLE rename_db.r1 (name String) Engine=Memory();
SHOW TABLES FROM rename_db;

RENAME TABLE rename_db.r1 TO rename_db.r2;
SHOW TABLES FROM rename_db;

RENAME rename_db.r2 TO rename_db.r3;
SHOW TABLES FROM rename_db;

DROP DATABASE rename_db;

0 comments on commit 60fe7c5

Please sign in to comment.