[Doc] Update CREATE TABLE AS SELECT.md add PK model desc (#27978)
This commit is contained in:
parent
7c1910c2d7
commit
cddb9cf98a
|
|
@ -13,6 +13,7 @@ You can submit an asynchronous CTAS task using [SUBMIT TASK](../data-manipulatio
|
|||
```SQL
|
||||
CREATE TABLE [IF NOT EXISTS] [database.]table_name
|
||||
[(column_name [, column_name2, ...]]
|
||||
[key_desc]
|
||||
[COMMENT "table comment"]
|
||||
[partition_desc]
|
||||
[distribution_desc]
|
||||
|
|
@ -27,6 +28,7 @@ You can submit an asynchronous CTAS task using [SUBMIT TASK](../data-manipulatio
|
|||
SUBMIT [/*+ SET_VAR(key=value) */] TASK [[database.]<task_name>]AS
|
||||
CREATE TABLE [IF NOT EXISTS] [database.]table_name
|
||||
[(column_name [, column_name2, ...]]
|
||||
[key_desc]
|
||||
[COMMENT "table comment"]
|
||||
[partition_desc]
|
||||
[distribution_desc]
|
||||
|
|
@ -39,6 +41,7 @@ You can submit an asynchronous CTAS task using [SUBMIT TASK](../data-manipulatio
|
|||
| **Parameter** | **Required** | **Description** |
|
||||
| ----------------- | ------------ | ------------------------------------------------------------ |
|
||||
| column_name | Yes | The name of a column in the new table. You do not need to specify the data type for the column. StarRocks automatically specifies an appropriate data type for the column . StarRocks converts FLOAT and DOUBLE data into DECIMAL(38,9) data. StarRocks also converts CHAR, VARCHAR, and STRING data into VARCHAR(65533) data. |
|
||||
| key_desc | No | The syntax is `key_type ( <col_name1> [, <col_name2> , ...])`.<br>**Parameters**:<ul><li>`key_type`: [the key type of the new table](../../../table_design/table_types/table_types.md). Valid values: `DUPLICATE KEY` and `PRIMARY KEY`. Default value: `DUPLICATE KEY`.</li><li> `col_name`: the column to form the key.</li></ul> |
|
||||
| COMMENT | No | The comment of the new table. |
|
||||
| partition_desc | No | The partitioning method of the new table. If you do not specify this parameter, by default, the new table has no partition. For more information about partitioning, see CREATE TABLE. |
|
||||
| distribution_desc | No | The bucketing method of the new table. If you do not specify this parameter, the bucket column defaults to the column with the highest cardinality collected by the cost-based optimizer (CBO). The number of buckets defaults to 10. If the CBO does not collect information about the cardinality, the bucket column defaults to the first column in the new table. For more information about bucketing, see CREATE TABLE. |
|
||||
|
|
@ -50,7 +53,7 @@ You can submit an asynchronous CTAS task using [SUBMIT TASK](../data-manipulatio
|
|||
- The CTAS statement can only create a new table that meets the following requirements:
|
||||
- `ENGINE` is `OLAP`.
|
||||
|
||||
- The table is a Duplicate Key table.
|
||||
- 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.
|
||||
|
||||
|
|
@ -109,7 +112,19 @@ SELECT * FROM employee_new;
|
|||
+------------+
|
||||
```
|
||||
|
||||
Example 4: Synchronously query four tables, including `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.
|
||||
Example 4: Use CTAS to create a Primary Key table. Note that the number of data rows in the Primary Key table may be less than that in the query result. It is because the [Primary Key](../../../table_design/table_types/primary_key_table.md) table only stores the most recent data row among a group of rows that have the same primary key.
|
||||
|
||||
```SQL
|
||||
CREATE TABLE employee_new
|
||||
PRIMARY KEY(order_id)
|
||||
AS SELECT
|
||||
order_list.order_id,
|
||||
sum(goods.price) as total
|
||||
FROM order_list INNER JOIN goods ON goods.item_id1 = order_list.item_id2
|
||||
GROUP BY order_id;
|
||||
```
|
||||
|
||||
Example 5: Synchronously query four tables, including `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.
|
||||
|
||||
```SQL
|
||||
CREATE TABLE lineorder_flat
|
||||
|
|
@ -161,7 +176,7 @@ INNER JOIN supplier AS s ON s.S_SUPPKEY = l.LO_SUPPKEY
|
|||
INNER JOIN part AS p ON p.P_PARTKEY = l.LO_PARTKEY;
|
||||
```
|
||||
|
||||
Example 5: Asynchronously query the 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.
|
||||
Example 6: Asynchronously query the 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.
|
||||
|
||||
```Plain%20Text
|
||||
SUBMIT TASK AS CREATE TABLE order_statistics AS SELECT COUNT(*) as count FROM order_detail;
|
||||
|
|
|
|||
Loading…
Reference in New Issue