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.
Matriz (t)
Una matriz de T
-tipo de artículos. T
puede ser cualquier tipo de datos, incluida una matriz.
Creación de una matriz
Puede usar una función para crear una matriz:
array(T)
También puede usar corchetes.
[]
Ejemplo de creación de una matriz:
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) │
└───────┴────────────────────┘
Trabajar con tipos de datos
Al crear una matriz sobre la marcha, ClickHouse define automáticamente el tipo de argumento como el tipo de datos más estrecho que puede almacenar todos los argumentos enumerados. Si hay alguna NULL o literal NULL valores, el tipo de un elemento de matriz también se convierte en NULL.
Si ClickHouse no pudo determinar el tipo de datos, genera una excepción. Por ejemplo, esto sucede cuando se intenta crear una matriz con cadenas y números simultáneamente (SELECT array(1, 'a')
).
Ejemplos de detección automática de tipos de datos:
SELECT array(1, 2, NULL) AS x, toTypeName(x)
┌─x──────────┬─toTypeName(array(1, 2, NULL))─┐
│ [1,2,NULL] │ Array(Nullable(UInt8)) │
└────────────┴───────────────────────────────┘
Si intenta crear una matriz de tipos de datos incompatibles, ClickHouse produce una excepción:
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.