clickhouse を使っていてテーブルがたくさんある中で、特定のカラムを探したい場合があります。
そんな時は、system.columns というテーブルからカラム名を検索する方法があります。
このテーブルを使用すると、DESCRIBE TABLE クエリと同様の情報を取得でき、一度に複数のテーブルから検索することができます。
clickhouse で特定のカラムを探す方法
クエリ
以下のようなクエリでカラムの検索が行えます。
SELECT table, name FROM system.columns WHERE (database = '{{データベース名}}') AND (name = '{{カラム名}}') LIMIT 10;
system.columns のカラム
system.columns は次の列が含まれています。
| カラム | 型 | 情報 |
|---|---|---|
| database | (文字列) | データベース名 |
| table | (文字列) | テーブル名 |
| name | (文字列) | 列名 |
| type | (文字列) | 列タイプ |
| position | (Ulnt64) | 1で始まるテーブル内の列の序数位置 |
| default_kind | (文字列) | デフォルト値の式タイプ |
| default_expression | (文字列) | デフォルト値の式 |
| data_compressed_bytes | (Ulnt64) | 圧縮データのサイズ |
| data_uncompressed_bytes | (Ulnt64) | 解凍されたデータのサイズ |
| marks_bytes | (UInt64) | マークのサイズ(バイト単位) |
| comment | (文字列) | 列のコメント |
| is_in_partition_key | (UInt8) | 列パーティションフラグ |
| is_in_sorting_key | (UInt8) | 列ソートフラグ |
| is_in_sampling_key | (UInt8) | 列サンプリングキーフラグ |
| compression_codec | (文字列) | 圧縮コーデック名 |
| character_octet_length | (UInt64) | - |
| numeric_precision | (UInt64) | - |
| numeric_precision_radix | (UInt64) | - |
| numeric_scale | (UInt64) | 近似数値データ |
| datetime_precision | (UInt64) | データ型の10進精度 |