2020-03-30 12:48:55 +00:00
|
|
|
|
---
|
|
|
|
|
machine_translated: true
|
2020-05-15 04:34:54 +00:00
|
|
|
|
machine_translated_rev: 72537a2d527c63c07aa5d2361a8829f3895cf2bd
|
2020-04-04 09:15:31 +00:00
|
|
|
|
toc_priority: 63
|
|
|
|
|
toc_title: "\u06A9\u0627\u0631 \u0628\u0627 Nullable \u0627\u0633\u062A\u062F\u0644\
|
|
|
|
|
\u0627\u0644"
|
2020-03-30 12:48:55 +00:00
|
|
|
|
---
|
|
|
|
|
|
2020-05-15 04:34:54 +00:00
|
|
|
|
# توابع برای کار با Nullable مصالح {#functions-for-working-with-nullable-aggregates}
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
## isNull {#isnull}
|
|
|
|
|
|
2020-05-06 06:13:29 +00:00
|
|
|
|
بررسی اینکه بحث چیست [NULL](../../sql-reference/syntax.md#null-literal).
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
isNull(x)
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**پارامترها**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
- `x` — A value with a non-compound data type.
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مقدار بازگشتی**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
- `1` اگر `x` هست `NULL`.
|
|
|
|
|
- `0` اگر `x` نیست `NULL`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مثال**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
جدول ورودی
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─x─┬────y─┐
|
|
|
|
|
│ 1 │ ᴺᵁᴸᴸ │
|
|
|
|
|
│ 2 │ 3 │
|
|
|
|
|
└───┴──────┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
پرسوجو
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT x FROM t_null WHERE isNull(y)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─x─┐
|
|
|
|
|
│ 1 │
|
|
|
|
|
└───┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
## اینترنت {#isnotnull}
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-05-06 06:13:29 +00:00
|
|
|
|
بررسی اینکه بحث چیست [NULL](../../sql-reference/syntax.md#null-literal).
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
isNotNull(x)
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**پارامترها:**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
- `x` — A value with a non-compound data type.
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مقدار بازگشتی**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
- `0` اگر `x` هست `NULL`.
|
|
|
|
|
- `1` اگر `x` نیست `NULL`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مثال**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
جدول ورودی
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─x─┬────y─┐
|
|
|
|
|
│ 1 │ ᴺᵁᴸᴸ │
|
|
|
|
|
│ 2 │ 3 │
|
|
|
|
|
└───┴──────┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
پرسوجو
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT x FROM t_null WHERE isNotNull(y)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─x─┐
|
|
|
|
|
│ 2 │
|
|
|
|
|
└───┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
## فلز کاری {#coalesce}
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
چک از چپ به راست چه `NULL` استدلال به تصویب رسید و اولین غیر گرداند-`NULL` استدلال کردن.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
coalesce(x,...)
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**پارامترها:**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
- هر تعداد از پارامترهای یک نوع غیر مرکب. تمام پارامترها باید با نوع داده سازگار باشند.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مقادیر بازگشتی**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
- اولین غیر-`NULL` استدلال کردن.
|
|
|
|
|
- `NULL`, اگر همه استدلال ها `NULL`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مثال**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
یک لیست از مخاطبین است که ممکن است راه های متعدد برای تماس با مشتری مشخص را در نظر بگیرید.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─name─────┬─mail─┬─phone─────┬──icq─┐
|
|
|
|
|
│ client 1 │ ᴺᵁᴸᴸ │ 123-45-67 │ 123 │
|
|
|
|
|
│ client 2 │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │
|
|
|
|
|
└──────────┴──────┴───────────┴──────┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
این `mail` و `phone` زمینه های رشته نوع هستند, اما `icq` زمینه است `UInt32` بنابراین نیاز به تبدیل شدن به `String`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
دریافت اولین روش تماس در دسترس برای مشتری از لیست تماس:
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` 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}
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
بازگرداندن یک مقدار جایگزین اگر استدلال اصلی است `NULL`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
ifNull(x,alt)
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**پارامترها:**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
- `x` — The value to check for `NULL`.
|
2020-04-04 09:15:31 +00:00
|
|
|
|
- `alt` — The value that the function returns if `x` هست `NULL`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مقادیر بازگشتی**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
- مقدار `x` اگر `x` نیست `NULL`.
|
|
|
|
|
- مقدار `alt` اگر `x` هست `NULL`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مثال**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT ifNull('a', 'b')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─ifNull('a', 'b')─┐
|
|
|
|
|
│ a │
|
|
|
|
|
└──────────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT ifNull(NULL, 'b')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─ifNull(NULL, 'b')─┐
|
|
|
|
|
│ b │
|
|
|
|
|
└───────────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## nullIf {#nullif}
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
بازگشت `NULL` اگر استدلال برابر هستند.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
nullIf(x, y)
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**پارامترها:**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
`x`, `y` — Values for comparison. They must be compatible types, or ClickHouse will generate an exception.
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مقادیر بازگشتی**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
- `NULL`, اگر استدلال برابر هستند.
|
|
|
|
|
- این `x` ارزش, اگر استدلال برابر نیست.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مثال**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT nullIf(1, 1)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─nullIf(1, 1)─┐
|
|
|
|
|
│ ᴺᵁᴸᴸ │
|
|
|
|
|
└──────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT nullIf(1, 2)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─nullIf(1, 2)─┐
|
|
|
|
|
│ 1 │
|
|
|
|
|
└──────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
## قابل قبول {#assumenotnull}
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-30 18:19:18 +00:00
|
|
|
|
نتایج در ارزش نوع [Nullable](../../sql-reference/data-types/nullable.md) برای یک غیر- `Nullable`, اگر مقدار است `NULL`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
assumeNotNull(x)
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**پارامترها:**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
- `x` — The original value.
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مقادیر بازگشتی**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
- مقدار اصلی از غیر-`Nullable` نوع, اگر نیست `NULL`.
|
|
|
|
|
- مقدار پیش فرض برای غیر-`Nullable` نوع اگر مقدار اصلی بود `NULL`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مثال**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
در نظر بگیرید که `t_null` جدول
|
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 │
|
|
|
|
|
└───┴──────┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
درخواست `assumeNotNull` تابع به `y` ستون.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` 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 │
|
|
|
|
|
└──────────────────────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
## قابل تنظیم {#tonullable}
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
تبدیل نوع استدلال به `Nullable`.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
toNullable(x)
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**پارامترها:**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
- `x` — The value of any non-compound type.
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مقدار بازگشتی**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
- مقدار ورودی با یک `Nullable` نوع.
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
**مثال**
|
2020-03-30 12:48:55 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT toTypeName(10)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─toTypeName(10)─┐
|
|
|
|
|
│ UInt8 │
|
|
|
|
|
└────────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT toTypeName(toNullable(10))
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─toTypeName(toNullable(10))─┐
|
|
|
|
|
│ Nullable(UInt8) │
|
|
|
|
|
└────────────────────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
2020-04-04 09:15:31 +00:00
|
|
|
|
[مقاله اصلی](https://clickhouse.tech/docs/en/query_language/functions/functions_for_nulls/) <!--hide-->
|