system.columns

此系统表包含所有表中列的信息。

你可以使用这个表来获得类似于 DESCRIBE TABLE 查询的信息,但是可以同时获得多个表的信息。

临时表中的列只在创建它们的会话中的 system.columns 中才可见,并且它们的 database 字段显示为空。

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

  • database (String) — 数据库名称。
  • table (String) — 表名。
  • name (String) — 列名。
  • type (String) — 列类型。
  • position (UInt64) — 列在表中的顺序位置,从1开始。
  • default_kind (String) — 默认值的表达式类型(DEFAULT, MATERIALIZED, ALIAS) ,如果没有定义,则为空字符串。
  • 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 中,对于整数类型是比特率(bitness),对于 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 值。

示例

  1. SELECT * FROM system.columns LIMIT 2 FORMAT Vertical;
  1. Row 1:
  2. ──────
  3. database: INFORMATION_SCHEMA
  4. table: COLUMNS
  5. name: table_catalog
  6. type: String
  7. position: 1
  8. default_kind:
  9. default_expression:
  10. data_compressed_bytes: 0
  11. data_uncompressed_bytes: 0
  12. marks_bytes: 0
  13. comment:
  14. is_in_partition_key: 0
  15. is_in_sorting_key: 0
  16. is_in_primary_key: 0
  17. is_in_sampling_key: 0
  18. compression_codec:
  19. character_octet_length: ᴺᵁᴸᴸ
  20. numeric_precision: ᴺᵁᴸᴸ
  21. numeric_precision_radix: ᴺᵁᴸᴸ
  22. numeric_scale: ᴺᵁᴸᴸ
  23. datetime_precision: ᴺᵁᴸᴸ
  24. Row 2:
  25. ──────
  26. database: INFORMATION_SCHEMA
  27. table: COLUMNS
  28. name: table_schema
  29. type: String
  30. position: 2
  31. default_kind:
  32. default_expression:
  33. data_compressed_bytes: 0
  34. data_uncompressed_bytes: 0
  35. marks_bytes: 0
  36. comment:
  37. is_in_partition_key: 0
  38. is_in_sorting_key: 0
  39. is_in_primary_key: 0
  40. is_in_sampling_key: 0
  41. compression_codec:
  42. character_octet_length: ᴺᵁᴸᴸ
  43. numeric_precision: ᴺᵁᴸᴸ
  44. numeric_precision_radix: ᴺᵁᴸᴸ
  45. numeric_scale: ᴺᵁᴸᴸ
  46. datetime_precision: ᴺᵁᴸᴸ

原文