mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Merge pull request #55373 from lingtaolf/enhancement/rename_without_keyword
Support rename table without keyword TABLE
This commit is contained in:
commit
eeff98f3a3
@ -16,7 +16,7 @@ The `RENAME` query is supported by the [Atomic](../../engines/database-engines/a
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
RENAME DATABASE|TABLE|DICTIONARY name TO new_name [,...] [ON CLUSTER cluster]
|
||||
RENAME [DATABASE|TABLE|DICTIONARY] name TO new_name [,...] [ON CLUSTER cluster]
|
||||
```
|
||||
|
||||
## RENAME DATABASE
|
||||
@ -48,6 +48,11 @@ RENAME TABLE [db1.]name1 TO [db2.]name2 [,...] [ON CLUSTER cluster]
|
||||
RENAME TABLE table_A TO table_A_bak, table_B TO table_B_bak;
|
||||
```
|
||||
|
||||
And you can use a simpler sql:
|
||||
```sql
|
||||
RENAME table_A TO table_A_bak, table_B TO table_B_bak;
|
||||
```
|
||||
|
||||
## RENAME DICTIONARY
|
||||
|
||||
Renames one or several dictionaries. This query can be used to move dictionaries between databases.
|
||||
|
@ -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");
|
||||
@ -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;
|
||||
@ -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_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.ignore(pos, expected))
|
||||
;
|
||||
else
|
||||
return false;
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
r1
|
||||
r1_bak
|
||||
r1
|
||||
r1_bak
|
||||
r2_bak
|
||||
test_dictionary
|
||||
test_dictionary_2
|
@ -0,0 +1,42 @@
|
||||
DROP DATABASE IF EXISTS {CLICKHOUSE_DATABASE:Identifier};
|
||||
CREATE DATABASE IF NOT EXISTS {CLICKHOUSE_DATABASE:Identifier};
|
||||
|
||||
CREATE TABLE IF NOT EXISTS {CLICKHOUSE_DATABASE:Identifier}.r1 (name String) Engine=Memory();
|
||||
SHOW TABLES FROM {CLICKHOUSE_DATABASE:Identifier};
|
||||
|
||||
RENAME TABLE {CLICKHOUSE_DATABASE:Identifier}.r1 TO {CLICKHOUSE_DATABASE:Identifier}.r1_bak;
|
||||
SHOW TABLES FROM {CLICKHOUSE_DATABASE:Identifier};
|
||||
|
||||
RENAME {CLICKHOUSE_DATABASE:Identifier}.r1_bak TO {CLICKHOUSE_DATABASE:Identifier}.r1;
|
||||
SHOW TABLES FROM {CLICKHOUSE_DATABASE:Identifier};
|
||||
|
||||
CREATE TABLE IF NOT EXISTS {CLICKHOUSE_DATABASE:Identifier}.r2 (name String) Engine=Memory();
|
||||
RENAME {CLICKHOUSE_DATABASE:Identifier}.r1 TO {CLICKHOUSE_DATABASE:Identifier}.r1_bak,
|
||||
{CLICKHOUSE_DATABASE:Identifier}.r2 TO {CLICKHOUSE_DATABASE:Identifier}.r2_bak;
|
||||
SHOW TABLES FROM {CLICKHOUSE_DATABASE:Identifier};
|
||||
|
||||
CREATE TABLE IF NOT EXISTS {CLICKHOUSE_DATABASE:Identifier}.source_table (
|
||||
id UInt64,
|
||||
value String
|
||||
) ENGINE = Memory;
|
||||
|
||||
CREATE DICTIONARY IF NOT EXISTS {CLICKHOUSE_DATABASE:Identifier}.test_dictionary
|
||||
(
|
||||
id UInt64,
|
||||
value String
|
||||
)
|
||||
PRIMARY KEY id
|
||||
SOURCE(CLICKHOUSE(TABLE '{CLICKHOUSE_DATABASE:String}.dictionary_table'))
|
||||
LAYOUT(FLAT())
|
||||
LIFETIME(MIN 0 MAX 1000);
|
||||
|
||||
SHOW DICTIONARIES FROM {CLICKHOUSE_DATABASE:Identifier};
|
||||
|
||||
RENAME {CLICKHOUSE_DATABASE:Identifier}.test_dictionary TO {CLICKHOUSE_DATABASE:Identifier}.test_dictionary_2;
|
||||
SHOW DICTIONARIES FROM {CLICKHOUSE_DATABASE:Identifier};
|
||||
|
||||
SHOW DATABASES LIKE '{CLICKHOUSE_DATABASE:String}';
|
||||
RENAME {CLICKHOUSE_DATABASE:Identifier} TO {CLICKHOUSE_DATABASE_1:Identifier}; -- { serverError UNKNOWN_TABLE }
|
||||
SHOW DATABASES LIKE '{CLICKHOUSE_DATABASE:String}';
|
||||
|
||||
DROP DATABASE IF EXISTS {CLICKHOUSE_DATABASE:Identifier};
|
Loading…
Reference in New Issue
Block a user