2020-04-08 14:22:25 +00:00
|
|
|
|
---
|
2022-08-26 19:07:59 +00:00
|
|
|
|
slug: /zh/engines/table-engines/special/generate
|
2022-04-10 23:08:18 +00:00
|
|
|
|
sidebar_position: 46
|
|
|
|
|
sidebar_label: 随机数生成
|
2020-04-08 14:22:25 +00:00
|
|
|
|
---
|
|
|
|
|
|
2020-06-18 15:03:32 +00:00
|
|
|
|
# 随机数生成表引擎 {#table_engines-generate}
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2021-07-29 15:20:55 +00:00
|
|
|
|
随机数生成表引擎为指定的表模式生成随机数
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
|
|
|
|
使用示例:
|
2020-06-18 15:03:32 +00:00
|
|
|
|
- 测试时生成可复写的大表
|
|
|
|
|
- 为复杂测试生成随机输入
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2020-06-18 15:03:32 +00:00
|
|
|
|
## CH服务端的用法 {#usage-in-clickhouse-server}
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
ENGINE = GenerateRandom(random_seed, max_string_length, max_array_length)
|
|
|
|
|
```
|
|
|
|
|
|
2020-06-18 15:03:32 +00:00
|
|
|
|
生成数据时,通过`max_array_length` 设置array列的最大长度, `max_string_length`设置string数据的最大长度
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2020-06-18 15:03:32 +00:00
|
|
|
|
该引擎仅支持 `SELECT` 查询语句.
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2020-06-18 15:03:32 +00:00
|
|
|
|
该引擎支持能在表中存储的所有数据类型 [DataTypes](../../../sql-reference/data-types/index.md) ,除了 `LowCardinality` 和 `AggregateFunction`.
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2020-06-18 15:03:32 +00:00
|
|
|
|
## 示例 {#example}
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2020-06-18 15:03:32 +00:00
|
|
|
|
**1.** 设置 `generate_engine_table` 引擎表:
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
CREATE TABLE generate_engine_table (name String, value UInt32) ENGINE = GenerateRandom(1, 5, 3)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**2.** 查询数据:
|
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT * FROM generate_engine_table LIMIT 3
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─name─┬──────value─┐
|
|
|
|
|
│ c4xJ │ 1412771199 │
|
|
|
|
|
│ r │ 1791099446 │
|
|
|
|
|
│ 7#$ │ 124312908 │
|
|
|
|
|
└──────┴────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-06-18 15:03:32 +00:00
|
|
|
|
## 实现细节 {#details-of-implementation}
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2020-06-18 15:03:32 +00:00
|
|
|
|
- 以下特性不支持:
|
2020-04-08 14:22:25 +00:00
|
|
|
|
- `ALTER`
|
|
|
|
|
- `SELECT ... SAMPLE`
|
|
|
|
|
- `INSERT`
|
2020-06-18 15:03:32 +00:00
|
|
|
|
- Indices
|
|
|
|
|
- Replication
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2021-09-19 20:05:54 +00:00
|
|
|
|
[原始文档](https://clickhouse.com/docs/en/operations/table_engines/generate/) <!--hide-->
|