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

columns

包含有关所有表中列的信息。

您可以使用此表获取类似于 DESCRIBE TABLE 查询的信息,但可以一次获取多个表的信息。

来自 临时表 的列仅在创建它们的会话中的 system.columns 中可见。它们显示时 database 字段为空。

system.columns 表包含以下列(列类型在括号中显示)

  • database (String) — 数据库名称。
  • table (String) — 表名称。
  • name (String) — 列名称。
  • type (String) — 列类型。
  • position (UInt64) — 列在表中的序号位置,从 1 开始。
  • default_kind (String) — 默认值的表达式类型(DEFAULTMATERIALIZEDALIAS),如果未定义,则为空字符串。
  • default_expression (String) — 默认值的表达式,如果未定义,则为空字符串。
  • data_compressed_bytes (UInt64) — 压缩数据的大小,以字节为单位。
  • data_uncompressed_bytes (UInt64) — 解压缩数据的大小,以字节为单位。
  • marks_bytes (UInt64) — 标记的大小,以字节为单位。
  • comment (String) — 列的注释,如果未定义,则为空字符串。
  • is_in_partition_key (UInt8) — 标志,指示列是否在分区表达式中。
  • is_in_sorting_key (UInt8) — 标志,指示列是否在排序键表达式中。
  • is_in_primary_key (UInt8) — 标志,指示列是否在主键表达式中。
  • is_in_sampling_key (UInt8) — 标志,指示列是否在抽样键表达式中。
  • compression_codec (String) — 压缩编解码器名称。
  • character_octet_length (Nullable(UInt64)) — 二进制数据、字符数据或文本数据和图像的最大长度(以字节为单位)。在 ClickHouse 中仅对 FixedString 数据类型有意义。否则,返回 NULL 值。
  • numeric_precision (Nullable(UInt64)) — 近似数值数据、精确数值数据、整数数据或货币数据的精度。在 ClickHouse 中,对于整数类型,它是位宽;对于 Decimal 类型,它是十进制精度。否则,返回 NULL 值。
  • numeric_precision_radix (Nullable(UInt64)) — 数字系统的基数是近似数值数据、精确数值数据、整数数据或货币数据的精度。在 ClickHouse 中,整数类型为 2,Decimal 类型为 10。否则,返回 NULL 值。
  • numeric_scale (Nullable(UInt64)) — 近似数值数据、精确数值数据、整数数据或货币数据的标度。在 ClickHouse 中仅对 Decimal 类型有意义。否则,返回 NULL 值。
  • datetime_precision (Nullable(UInt64)) — DateTime64 数据类型的十进制精度。对于其他数据类型,返回 NULL 值。

示例

SELECT * FROM system.columns LIMIT 2 FORMAT Vertical;
Row 1:
──────
database: INFORMATION_SCHEMA
table: COLUMNS
name: table_catalog
type: String
position: 1
default_kind:
default_expression:
data_compressed_bytes: 0
data_uncompressed_bytes: 0
marks_bytes: 0
comment:
is_in_partition_key: 0
is_in_sorting_key: 0
is_in_primary_key: 0
is_in_sampling_key: 0
compression_codec:
character_octet_length: ᴺᵁᴸᴸ
numeric_precision: ᴺᵁᴸᴸ
numeric_precision_radix: ᴺᵁᴸᴸ
numeric_scale: ᴺᵁᴸᴸ
datetime_precision: ᴺᵁᴸᴸ

Row 2:
──────
database: INFORMATION_SCHEMA
table: COLUMNS
name: table_schema
type: String
position: 2
default_kind:
default_expression:
data_compressed_bytes: 0
data_uncompressed_bytes: 0
marks_bytes: 0
comment:
is_in_partition_key: 0
is_in_sorting_key: 0
is_in_primary_key: 0
is_in_sampling_key: 0
compression_codec:
character_octet_length: ᴺᵁᴸᴸ
numeric_precision: ᴺᵁᴸᴸ
numeric_precision_radix: ᴺᵁᴸᴸ
numeric_scale: ᴺᵁᴸᴸ
datetime_precision: ᴺᵁᴸᴸ