Help wanted!
The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.
配列(t)
の配列 T
-タイプ項目。 T
配列を含む任意のデータ型を指定できます。
配列の作成
関数を使用して配列を作成できます:
array(T)
角括弧を使用することもできます。
[]
配列の作成例:
SELECT array(1, 2) AS x, toTypeName(x)
┌─x─────┬─toTypeName(array(1, 2))─┐
│ [1,2] │ Array(UInt8) │
└───────┴─────────────────────────┘
SELECT [1, 2] AS x, toTypeName(x)
┌─x─────┬─toTypeName([1, 2])─┐
│ [1,2] │ Array(UInt8) │
└───────┴────────────────────┘
データ型の操作
オンザフライで配列を作成するとき、ClickHouseは、リストされたすべての引数を格納できる最も狭いデータ型として引数型を自動的に定義します。 いずれかがある場合 Null可能 またはリテラル NULL 値を指定すると、配列要素の型も次のようになります Null可能.
ClickHouseがデータ型を判別できなかった場合、例外が生成されます。 たとえば、これは文字列と数値を同時に配列を作成しようとするときに発生します (SELECT array(1, 'a')
).
自動データ型検出の例:
SELECT array(1, 2, NULL) AS x, toTypeName(x)
┌─x──────────┬─toTypeName(array(1, 2, NULL))─┐
│ [1,2,NULL] │ Array(Nullable(UInt8)) │
└────────────┴───────────────────────────────┘
互換性のないデータ型の配列を作成しようとすると、ClickHouseは例外をスローします:
SELECT array(1, 'a')
Received exception from server (version 1.1.54388):
Code: 386. DB::Exception: Received from localhost:9000, 127.0.0.1. DB::Exception: There is no supertype for types UInt8, String because some of them are String/FixedString and some of them are not.