Files
doris/docs/en/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-TABLE-AS-SELECT.md
Stalary 70642e3bff [Doc] 添加CTAS文档 (#9454)
* ADD: 添加CTAS文档
2022-05-10 09:01:42 +08:00

2.0 KiB

title, language
title language
CREATE-TABLE-AS-SELECT en

CREATE-TABLE-AS-SELECT

Name

CREATE TABLE AS SELECT

Description

This statement creates the table structure by returning the results from the Select statement and imports the data at the same time

grammar:

CREATE TABLE table_name [( column_name_list )]
opt_engine opt_partition opt_properties KW_AS query_stmt

illustrate:

  • Fields of typedecimalare not currently supported
  • The user needs to haveSELECTpermission for the source table andCREATEpermission for the target database
  • After a table is created, data is imported. If the import fails, the table is deleted

Example

  1. Using the field names in the SELECT statement

    create table `test`.`select_varchar` 
    PROPERTIES(\"replication_num\" = \"1\") 
    as select * from `test`.`varchar_table`
    
  2. Custom field names (need to match the number of fields returned)

    create table `test`.`select_name`(user, testname, userstatus) 
    PROPERTIES(\"replication_num\" = \"1\") 
    as select vt.userId, vt.username, jt.status 
    from `test`.`varchar_table` vt join 
    `test`.`join_table` jt on vt.userId=jt.userId
    

Keywords

CREATE, TABLE, AS, SELECT

Best Practice