Syntax
-
Synchronously query a table and create a new table based on the query result, and then insert the query result into the new table.
-
Asynchronously query a table and create a new table based on the query result, and then insert the query result into the new table.
Parameters
Usage notes
- For Paimon CTAS, use a Paimon catalog for the target table. The database rejects a Unified Catalog target before creating the table. If you omit the catalog or database from the target name, the database uses the session’s current catalog or database. See Paimon CTAS for supported options and failure behavior.
-
The following defaults apply to OLAP targets.
-
The table is a Duplicate Key table by default. You can also specify it as a Primary Key table in
key_desc. - The sort keys are the first three columns, and the storage space of the data types of these three columns does not exceed 36 bytes.
-
The table is a Duplicate Key table by default. You can also specify it as a Primary Key table in
-
If the CTAS statement fails to execute due to reasons, such as an FE restart, one of the following issues may occur:
- A new table is created successfully but does not contain data.
- A new table fails to be created.
- After a new table is created, if multiple methods (such as INSERT INTO) are used to insert data into the new table, the method that completes the INSERT operation first will insert its data into the new table.
- After a new table is created, you need to manually grant permissions on this table to users.
- If you do not specify a name for a Task when you asynchronously query a table and create a new table based on the query result, the database automatically generates a name for the Task.
Examples
Example 1: Synchronously query a tableorder and create a new table order_new based on the query result, and then insert the query result into the new table.
k1, k2, and k3 columns in the table order and create a new table order_new based on the query result, and then insert the query result into the new table. Additionally, set the column names of the new table to a, b, and c.
salary column in the table employee and create a new table employee_new based on the query result, and then insert the query result into the new table. Additionally, set the column name of the new table to salary_max.
customer_id and first_name columns in the table customers and create a new table customers_new based on the query result, and then insert the query result into the new table. Additionally, set the column names of the new table to customer_id_new and first_name_new. Also, build a bitmap index for the column customer_id_new in the new table.
customers and create a new table customers_new based on the query result, and then insert the query result into the new table. Additionally, specify the new table as a Primary Key table, and specify its sort key as first_name and last_name.
lineorder, customer, supplier, and part and create a new table lineorder_flat based on the query result, and then insert the query result to the new table. Additionally, specify the partitioning method and bucketing method for the new table.
order_detail and create a new table order_statistics based on the query result, and then insert the query result into the new table.
SUCCESS.