ClickHouse/docs/fr/sql-reference/functions/functions-for-nulls.md

313 lines
6.8 KiB
Markdown
Raw Normal View History

2020-03-30 12:48:55 +00:00
---
machine_translated: true
2020-04-04 09:15:31 +00:00
machine_translated_rev: f865c9653f9df092694258e0ccdd733c339112f5
toc_priority: 63
toc_title: Travailler avec des arguments nullables
2020-03-30 12:48:55 +00:00
---
# Fonctions Pour Travailler Avec Des agrégats Nullables {#functions-for-working-with-nullable-aggregates}
2020-03-30 12:48:55 +00:00
## isNull {#isnull}
DOCS-624: Fixing links to nowhere (#10675) * enbaskakova-DOCSUP-652 (#101) * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" Co-authored-by: elenbaskakova <elenbaskakova@yandex-team.ru> Co-authored-by: BayoNet <da-daos@yandex.ru> * Revert "enbaskakova-DOCSUP-652 (#101)" (#107) This reverts commit 639fee7610f28e421d14e535b7def3f466e7efca. * CLICKHOUSEDOCS-624: Fixed links. Was 60, became 13. * CLICKHOUSEDOCS-624: Finished fix links in Enlish version. * CLICKHOUSEDOCS-624: Fixed RU links Co-authored-by: elenaspb2019 <47083263+elenaspb2019@users.noreply.github.com> Co-authored-by: elenbaskakova <elenbaskakova@yandex-team.ru> Co-authored-by: Sergei Shtykov <bayonet@yandex-team.ru>
2020-05-06 06:13:29 +00:00
Vérifie si largument est [NULL](../../sql-reference/syntax.md#null-literal).
2020-03-30 12:48:55 +00:00
``` sql
isNull(x)
```
**Paramètre**
- `x` — A value with a non-compound data type.
**Valeur renvoyée**
- `1` si `x` être `NULL`.
- `0` si `x` nest pas `NULL`.
2020-03-30 12:48:55 +00:00
**Exemple**
Table dentrée
2020-03-30 12:48:55 +00:00
``` text
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 3 │
└───┴──────┘
```
Requête
``` sql
SELECT x FROM t_null WHERE isNull(y)
```
``` text
┌─x─┐
│ 1 │
└───┘
```
## isNotNull {#isnotnull}
DOCS-624: Fixing links to nowhere (#10675) * enbaskakova-DOCSUP-652 (#101) * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" Co-authored-by: elenbaskakova <elenbaskakova@yandex-team.ru> Co-authored-by: BayoNet <da-daos@yandex.ru> * Revert "enbaskakova-DOCSUP-652 (#101)" (#107) This reverts commit 639fee7610f28e421d14e535b7def3f466e7efca. * CLICKHOUSEDOCS-624: Fixed links. Was 60, became 13. * CLICKHOUSEDOCS-624: Finished fix links in Enlish version. * CLICKHOUSEDOCS-624: Fixed RU links Co-authored-by: elenaspb2019 <47083263+elenaspb2019@users.noreply.github.com> Co-authored-by: elenbaskakova <elenbaskakova@yandex-team.ru> Co-authored-by: Sergei Shtykov <bayonet@yandex-team.ru>
2020-05-06 06:13:29 +00:00
Vérifie si largument est [NULL](../../sql-reference/syntax.md#null-literal).
2020-03-30 12:48:55 +00:00
``` sql
isNotNull(x)
```
**Paramètre:**
- `x` — A value with a non-compound data type.
**Valeur renvoyée**
- `0` si `x` être `NULL`.
- `1` si `x` nest pas `NULL`.
2020-03-30 12:48:55 +00:00
**Exemple**
Table dentrée
2020-03-30 12:48:55 +00:00
``` text
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 3 │
└───┴──────┘
```
Requête
``` sql
SELECT x FROM t_null WHERE isNotNull(y)
```
``` text
┌─x─┐
│ 2 │
└───┘
```
## fusionner {#coalesce}
Vérifie de gauche à droite si `NULL` les arguments ont été passés et renvoie le premier non-`NULL` argument.
``` sql
coalesce(x,...)
```
**Paramètre:**
- Nimporte quel nombre de paramètres dun type non composé. Tous les paramètres doivent être compatibles par type de données.
2020-03-30 12:48:55 +00:00
**Valeurs renvoyées**
- Le premier non-`NULL` argument.
- `NULL` si tous les arguments sont `NULL`.
**Exemple**
Considérez une liste de contacts qui peuvent spécifier plusieurs façons de contacter un client.
``` text
┌─name─────┬─mail─┬─phone─────┬──icq─┐
│ client 1 │ ᴺᵁᴸᴸ │ 123-45-67 │ 123 │
│ client 2 │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │
└──────────┴──────┴───────────┴──────┘
```
Le `mail` et `phone` les champs sont de type Chaîne de caractères, mais la `icq` le terrain est `UInt32`, de sorte quil doit être converti en `String`.
2020-03-30 12:48:55 +00:00
Obtenir la première méthode de contact pour le client à partir de la liste de contacts:
``` sql
SELECT coalesce(mail, phone, CAST(icq,'Nullable(String)')) FROM aBook
```
``` text
┌─name─────┬─coalesce(mail, phone, CAST(icq, 'Nullable(String)'))─┐
│ client 1 │ 123-45-67 │
│ client 2 │ ᴺᵁᴸᴸ │
└──────────┴──────────────────────────────────────────────────────┘
```
## ifNull {#ifnull}
Renvoie une valeur alternative si largument principal est `NULL`.
2020-03-30 12:48:55 +00:00
``` sql
ifNull(x,alt)
```
**Paramètre:**
- `x` — The value to check for `NULL`.
- `alt` — The value that the function returns if `x` être `NULL`.
**Valeurs renvoyées**
- Valeur `x`, si `x` nest pas `NULL`.
2020-03-30 12:48:55 +00:00
- Valeur `alt`, si `x` être `NULL`.
**Exemple**
``` sql
SELECT ifNull('a', 'b')
```
``` text
┌─ifNull('a', 'b')─┐
│ a │
└──────────────────┘
```
``` sql
SELECT ifNull(NULL, 'b')
```
``` text
┌─ifNull(NULL, 'b')─┐
│ b │
└───────────────────┘
```
## nullIf {#nullif}
Retourner `NULL` si les arguments sont égaux.
``` sql
nullIf(x, y)
```
**Paramètre:**
`x`, `y` — Values for comparison. They must be compatible types, or ClickHouse will generate an exception.
**Valeurs renvoyées**
- `NULL` si les arguments sont égaux.
- Le `x` valeur, si les arguments ne sont pas égaux.
**Exemple**
``` sql
SELECT nullIf(1, 1)
```
``` text
┌─nullIf(1, 1)─┐
│ ᴺᵁᴸᴸ │
└──────────────┘
```
``` sql
SELECT nullIf(1, 2)
```
``` text
┌─nullIf(1, 2)─┐
│ 1 │
└──────────────┘
```
## assumeNotNull {#assumenotnull}
Résultats dans une valeur de type [Nullable](../../sql-reference/data-types/nullable.md) pour un non- `Nullable` si la valeur nest pas `NULL`.
2020-03-30 12:48:55 +00:00
``` sql
assumeNotNull(x)
```
**Paramètre:**
- `x` — The original value.
**Valeurs renvoyées**
- La valeur dorigine du non-`Nullable` type, si elle nest pas `NULL`.
- La valeur par défaut pour le non-`Nullable` Tapez si la valeur dorigine était `NULL`.
2020-03-30 12:48:55 +00:00
**Exemple**
Envisager l `t_null` table.
2020-03-30 12:48:55 +00:00
``` sql
SHOW CREATE TABLE t_null
```
``` text
┌─statement─────────────────────────────────────────────────────────────────┐
│ CREATE TABLE default.t_null ( x Int8, y Nullable(Int8)) ENGINE = TinyLog │
└───────────────────────────────────────────────────────────────────────────┘
```
``` text
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 3 │
└───┴──────┘
```
Appliquer le `assumeNotNull` la fonction de la `y` colonne.
``` sql
SELECT assumeNotNull(y) FROM t_null
```
``` text
┌─assumeNotNull(y)─┐
│ 0 │
│ 3 │
└──────────────────┘
```
``` sql
SELECT toTypeName(assumeNotNull(y)) FROM t_null
```
``` text
┌─toTypeName(assumeNotNull(y))─┐
│ Int8 │
│ Int8 │
└──────────────────────────────┘
```
## toNullable {#tonullable}
Convertit le type dargument en `Nullable`.
2020-03-30 12:48:55 +00:00
``` sql
toNullable(x)
```
**Paramètre:**
- `x` — The value of any non-compound type.
**Valeur renvoyée**
- La valeur dentrée avec un `Nullable` type.
2020-03-30 12:48:55 +00:00
**Exemple**
``` sql
SELECT toTypeName(10)
```
``` text
┌─toTypeName(10)─┐
│ UInt8 │
└────────────────┘
```
``` sql
SELECT toTypeName(toNullable(10))
```
``` text
┌─toTypeName(toNullable(10))─┐
│ Nullable(UInt8) │
└────────────────────────────┘
```
[Article Original](https://clickhouse.tech/docs/en/query_language/functions/functions_for_nulls/) <!--hide-->