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.
Funciones para trabajar con agregados anulables
IsNull
Comprueba si el argumento es NULL.
isNull(x)
Parámetros
x
— A value with a non-compound data type.
Valor devuelto
1
six
serNULL
.0
six
no esNULL
.
Ejemplo
Tabla de entrada
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 3 │
└───┴──────┘
Consulta
SELECT x FROM t_null WHERE isNull(y)
┌─x─┐
│ 1 │
└───┘
isNotNull
Comprueba si el argumento es NULL.
isNotNull(x)
Parámetros:
x
— A value with a non-compound data type.
Valor devuelto
0
six
serNULL
.1
six
no esNULL
.
Ejemplo
Tabla de entrada
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 3 │
└───┴──────┘
Consulta
SELECT x FROM t_null WHERE isNotNull(y)
┌─x─┐
│ 2 │
└───┘
Coalesce
Comprueba de izquierda a derecha si NULL
se aprobaron argumentos y devuelve el primer no-NULL
argumento.
coalesce(x,...)
Parámetros:
- Cualquier número de parámetros de un tipo no compuesto. Todos los parámetros deben ser compatibles por tipo de datos.
Valores devueltos
- El primer no-
NULL
argumento. NULL
si todos los argumentos sonNULL
.
Ejemplo
Considere una lista de contactos que pueden especificar varias formas de contactar a un cliente.
┌─name─────┬─mail─┬─phone─────┬──icq─┐
│ client 1 │ ᴺᵁᴸᴸ │ 123-45-67 │ 123 │
│ client 2 │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │
└──────────┴──────┴───────────┴──────┘
El mail
y phone
los campos son de tipo String, pero el icq
campo UInt32
, por lo que necesita ser convertido a String
.
Obtenga el primer método de contacto disponible para el cliente de la lista de contactos:
SELECT coalesce(mail, phone, CAST(icq,'Nullable(String)')) FROM aBook
┌─name─────┬─coalesce(mail, phone, CAST(icq, 'Nullable(String)'))─┐
│ client 1 │ 123-45-67 │
│ client 2 │ ᴺᵁᴸᴸ │
└──────────┴──────────────────────────────────────────────────────┘
ifNull
Devuelve un valor alternativo si el argumento principal es NULL
.
ifNull(x,alt)
Parámetros:
x
— The value to check forNULL
.alt
— The value that the function returns ifx
serNULL
.
Valores devueltos
- Valor
x
, six
no esNULL
. - Valor
alt
, six
serNULL
.
Ejemplo
SELECT ifNull('a', 'b')
┌─ifNull('a', 'b')─┐
│ a │
└──────────────────┘
SELECT ifNull(NULL, 'b')
┌─ifNull(NULL, 'b')─┐
│ b │
└───────────────────┘
nullIf
Devoluciones NULL
si los argumentos son iguales.
nullIf(x, y)
Parámetros:
x
, y
— Values for comparison. They must be compatible types, or ClickHouse will generate an exception.
Valores devueltos
NULL
si los argumentos son iguales.- El
x
valor, si los argumentos no son iguales.
Ejemplo
SELECT nullIf(1, 1)
┌─nullIf(1, 1)─┐
│ ᴺᵁᴸᴸ │
└──────────────┘
SELECT nullIf(1, 2)
┌─nullIf(1, 2)─┐
│ 1 │
└──────────────┘
assumeNotNull
Resultados en un valor de tipo NULL para un no- Nullable
si el valor no es NULL
.
assumeNotNull(x)
Parámetros:
x
— The original value.
Valores devueltos
- El valor original del-
Nullable
tipo, si no esNULL
. - El valor predeterminado para el-
Nullable
tipo si el valor original fueNULL
.
Ejemplo
Considere el t_null
tabla.
SHOW CREATE TABLE t_null
┌─statement─────────────────────────────────────────────────────────────────┐
│ CREATE TABLE default.t_null ( x Int8, y Nullable(Int8)) ENGINE = TinyLog │
└───────────────────────────────────────────────────────────────────────────┘
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 3 │
└───┴──────┘
Aplicar el assumeNotNull
función a la y
columna.
SELECT assumeNotNull(y) FROM t_null
┌─assumeNotNull(y)─┐
│ 0 │
│ 3 │
└──────────────────┘
SELECT toTypeName(assumeNotNull(y)) FROM t_null
┌─toTypeName(assumeNotNull(y))─┐
│ Int8 │
│ Int8 │
└──────────────────────────────┘
Acerca de Nosotros
Convierte el tipo de argumento a Nullable
.
toNullable(x)
Parámetros:
x
— The value of any non-compound type.
Valor devuelto
- El valor de entrada con un
Nullable
tipo.
Ejemplo
SELECT toTypeName(10)
┌─toTypeName(10)─┐
│ UInt8 │
└────────────────┘
SELECT toTypeName(toNullable(10))
┌─toTypeName(toNullable(10))─┐
│ Nullable(UInt8) │
└────────────────────────────┘