Skip to content

[Proposal]Support new syntax CREATE TABLE LIKE to create a new table from existed table #4355

@WingsGo

Description

@WingsGo

Is your feature request related to a problem? Please describe.
In some scenario, user may create a temp table whose schema is from a existed table for some reason such as load data to temp table and replace the new table, In this case, user must execute "SHOW CREATE TABLE old_table" and copy the text, change the table name, re-execute the sql in cli, it is not convient and waste some. So, I decide to support a new synax in create table.

Describe the solution you'd like
Synax: CREATE TABLE [IF NOT EXISTS] [db_name].table_name AS [db_name2].table_name2;
Behavior: The new create table synax will not only create a new table whose schema is the same as old_table, but also copy the old_table's partition, buckets, properties etc...

For example:

We have an existed table table_hash

CREATE TABLE example_db.table_hash
(
k1 TINYINT,
k2 DECIMAL(10, 2) DEFAULT "10.5",
v1 CHAR(10) REPLACE,
v2 INT SUM
)
ENGINE=olap
AGGREGATE KEY(k1, k2)
COMMENT "my first doris table"
DISTRIBUTED BY HASH(k1) BUCKETS 32
PROPERTIES ("storage_type"="column");

if we want create a new table named table_hash_tmp, we only need to execute sql CREATE TABLE example_db.table_hash_tmp AS example_db.table_hash, then we execute sql SHOW CREATE TABLE example_db.table_hash_tmp we will get:

CREATE TABLE example_db.table_hash_tmp
(
k1 TINYINT,
k2 DECIMAL(10, 2) DEFAULT "10.5",
v1 CHAR(10) REPLACE,
v2 INT SUM
)
ENGINE=olap
AGGREGATE KEY(k1, k2)
COMMENT "my first doris table"
DISTRIBUTED BY HASH(k1) BUCKETS 32
PROPERTIES ("storage_type"="column");

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Staleapi-reviewCategorizes an issue or PR as actively needing an API review.area/sqlIssues or PRs related to SQLkind/api-changeCategorizes issue or PR as related to adding, removing, or otherwise changing an API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions