ClickHouse常用系统表👇
表(system.tables)
SELECT `database`
,`name`
,`comment`
,`engine`
,`sorting_key`
,`partition_key`
,`total_rows`
,`total_bytes`
FROM system.tables
WHERE `database`='库名'
列名 | 数据类型 | 说明 |
---|
database | String | 库名 | name | String | 表名 | engine | String | 引擎名(不含参数) | is_temporary | UInt8 | 是否是临时表 | data_path | String | 数据在文件系统中的路径 | metadata_path | String | 元数据在文件系统中的路径 | metadata_modification_time | DateTime | 元数据的最新修改时间 | dependencies_database | Array(String) | 数据库依赖关系 | dependencies_table | Array(String) | 表依赖关系(基于当前表的 物化视图 表) | create_table_query | String | 建表SQL | engine_full | String | 表引擎的参数 | as_select | String | 视图的SELECT 语句 | partition_key | String | 分区键表达式 | sorting_key | String | 排序键表达式 | primary_key | String | 主键表达式 | sampling_key | String | 采样键表达式 | storage_policy | String | 存储 | total_rows | Nullable(UInt64) | 总行数,如果无法快速确定表中的确切行数,就返回为NULL (包括底层Buffer 表) | total_bytes | Nullable(UInt64) | 总字节数 如果无法快速确定存储表的确切字节数,就返回为NULL (不包括任何底层存储) 如果表数据存在磁盘,就返回使用的磁盘空间(压缩后) 如果表数据存储在内存,就返回在内存中使用的近似字节数 | lifetime_rows | Nullable(UInt64) | 服务启动后插入的总行数(只针对Buffer 表) | lifetime_bytes | Nullable(UInt64) | 服务启动后插入的总字节数(只针对Buffer 表) | comment | String | 表的注释 | has_own_data | UInt8 | 标志,表示表本身是否在磁盘上存储数据,或访问其他来源 |
列(system.columns)
SELECT `database`,`table`,`name`,`type`,`comment`
FROM system.columns
WHERE `database`='库名';
列名 | 数据类型 | 说明 |
---|
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) | 二进制数据、字符数据或文本数据和图像的最大长度(以字节为单位) 只对FixedString 数据类型有意义。否则,将返回NULL 值 | numeric_precision | Nullable(UInt64) | 近似数字型数据、精确数字型数据、整数型数据或货币数据的精度 对于整数类型是比特率(bitness),对于Decimal 类型是十进制精度。否则,将返回NULL 值 | numeric_precision_radix | Nullable(UInt64) | 数字系统的基数是近似数字型数据、精确数字型数据、整数型数据或货币数据的精度 对于整数类型是2,对于Decimal 类型是10。否则,将返回NULL 值 | numeric_scale | Nullable(UInt64) | 近似数字型数据、精确数字型数据、整数型数据或货币数据的比例 只对Decimal 类型有意义。否则,将返回NULL 值 | datetime_precision | Nullable(UInt64) | DateTime64 数据类型的小数精度。对于其他数据类型,将返回NULL 值 |
查询表和字段注释
SELECT c.`database` AS db_name
,c.`table` AS tb_name
,t.`comment` AS tb_comment
,c.`name` AS col_name
,c.`comment` AS col_comment
FROM system.columns c
LEFT JOIN system.tables t ON c.`table`=t.`name`
WHERE `database`='库名'
AND (t.`comment` LIKE '%中文注释%' OR c.`comment` LIKE '%中文注释%')
|