DESCRIBE 语句可用于返回表的列定义。
DESC|DESCRIBE TABLE [db.]table [INTO OUTFILE filename] [FORMAT format]
参数 | 是否必填 | 说明 |
|---|---|---|
INTO OUTFILE filename | 可选 | 将结果导出到文件(需绝对路径,如 |
FORMAT format | 可选 | 指定返回结果的格式(如 |
列名 | 说明 | 示例值 |
|---|---|---|
| 列名 |
|
| 列数据类型 |
|
| 列默认表达式中使用的子句: |
|
| DEFAULT 子句后指定的表达式 |
|
| 列注释文本 |
|
| 应用于该列的数据压缩编码 |
|
| TTL(生存时间)表达式 |
|
| 子列标识 | 需启用设置: |
-- 1. 创建数据库 CREATE DATABASE IF NOT EXISTS sample_db ON CLUSTER sample_cluster; --2. 创建表 DROP TABLE IF EXISTS sample_db.describe_table ON CLUSTER sample_cluster; CREATE TABLE sample_db.describe_table ON CLUSTER sample_cluster ( id UInt64, text String DEFAULT 'unknown' CODEC(ZSTD), user Tuple (name String, age UInt8) ) ENGINE = MergeTree() ORDER BY id; -- 3. 返回表中列的定义 DESCRIBE TABLE sample_db.describe_table; -- 输出结果示例如下: ┌─name─┬─type───────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐ │ id │ UInt64 │ │ │ │ │ │ │ text │ String │ DEFAULT │ 'unknown' │ │ ZSTD(1) │ │ │ user │ Tuple(name String, age UInt8) │ │ │ │ │ │ └────┴───────────────────┴─────────┴────────────┴───────┴───────────┴──────────┘