跳到主要内容
跳到主要内容

DESCRIBE TABLE

返回关于表列的信息。

语法

DESC|DESCRIBE TABLE [db.]table [INTO OUTFILE filename] [FORMAT format]

DESCRIBE 语句为每个表列返回一行,包含以下 String 值:

  • name — 列名。
  • type — 列类型。
  • default_type — 用于列 default expression 的子句:DEFAULTMATERIALIZEDALIAS。如果没有默认表达式,则返回空字符串。
  • default_expression — 在 DEFAULT 子句后指定的表达式。
  • comment列注释
  • codec_expression — 应用于列的 codec
  • ttl_expressionTTL 表达式。
  • is_subcolumn — 一个标志,对于内部子列等于 1。仅在通过 describe_include_subcolumns 设置启用子列描述时才会包含在结果中。

Nested 数据结构中的所有列单独描述。每列的名称以父列名和一个点作为前缀。

要显示其他数据类型的内部子列,请使用 describe_include_subcolumns 设置。

示例

查询:

CREATE TABLE describe_example (
    id UInt64, text String DEFAULT 'unknown' CODEC(ZSTD),
    user Tuple (name String, age UInt8)
) ENGINE = MergeTree() ORDER BY id;

DESCRIBE TABLE describe_example;
DESCRIBE TABLE describe_example SETTINGS describe_include_subcolumns=1;

结果:

┌─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) │              │                    │         │                  │                │
└──────┴───────────────────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘

第二个查询还额外显示了子列:

┌─name──────┬─type──────────────────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┬─is_subcolumn─┐
│ id        │ UInt64                        │              │                    │         │                  │                │            0 │
│ text      │ String                        │ DEFAULT      │ 'unknown'          │         │ ZSTD(1)          │                │            0 │
│ user      │ Tuple(name String, age UInt8) │              │                    │         │                  │                │            0 │
│ user.name │ String                        │              │                    │         │                  │                │            1 │
│ user.age  │ UInt8                         │              │                    │         │                  │                │            1 │
└───────────┴───────────────────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┴──────────────┘

另请参阅