Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/UserGuide/Master/Table/SQL-Manual/Basis-Function_apache.md
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,50 @@ Returns the first non-null value from the given list of parameters.
coalesce(value1, value2[, ...])
```

### 7.3 IF Expression
The IF expression has two forms: one that specifies only the true value, and another that specifies both the true value and the false value.

| Form | Description | Output Type Restrictions |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------ |
| `IF(condition, true_value)` | If the condition evaluates to true, `true_value` is computed and returned; otherwise, `null` is returned and `true_value` is not evaluated. | — |
| `IF(condition, true_value, false_value)` | If the condition evaluates to true, `true_value` is computed and returned; otherwise, `false_value` is computed and returned. | The data types of `true_value` and `false_value` **must be exactly the same**. Implicit type conversion is not supported. |

> Supported since V2.0.9-beta

**Examples:**

1. Equivalent examples of IF and CASE expressions:
```SQL
-- IF syntax
SELECT
device_id,
temperature,
IF(temperature > 85, 'High Value', 'Low Value')
FROM table1;

-- Equivalent CASE syntax
SELECT
device_id,
temperature,
CASE
WHEN temperature > 85 THEN 'High Value'
ELSE 'Low Value'
END
FROM table1;
```

2. Output type restriction examples:
```SQL
-- Succeeds
-- temperature (float) and humidity (float) have matching types
SELECT IF(temperature > 85, temperature, humidity) FROM table1;

-- Fails
-- temperature (float) and status (boolean) have mismatched types
SELECT IF(temperature > 85, temperature, status) FROM table1;
```


## 8. Conversion Functions

### 8.1 Conversion Functions
Expand Down
45 changes: 45 additions & 0 deletions src/UserGuide/Master/Table/SQL-Manual/Basis-Function_timecho.md
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,51 @@ Returns the first non-null value from the given list of parameters.
coalesce(value1, value2[, ...])
```

### 7.3 IF Expression

The IF expression has two forms: one that specifies only the true value, and another that specifies both the true value and the false value.

| Form | Description | Output Type Restrictions |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------ |
| `IF(condition, true_value)` | If the condition evaluates to true, `true_value` is computed and returned; otherwise, `null` is returned and `true_value` is not evaluated. | — |
| `IF(condition, true_value, false_value)` | If the condition evaluates to true, `true_value` is computed and returned; otherwise, `false_value` is computed and returned. | The data types of `true_value` and `false_value` **must be exactly the same**. Implicit type conversion is not supported. |

> Supported since V2.0.9.1

**Examples:**

1. Equivalent examples of IF and CASE expressions:
```SQL
-- IF syntax
SELECT
device_id,
temperature,
IF(temperature > 85, 'High Value', 'Low Value')
FROM table1;

-- Equivalent CASE syntax
SELECT
device_id,
temperature,
CASE
WHEN temperature > 85 THEN 'High Value'
ELSE 'Low Value'
END
FROM table1;
```

2. Output type restriction examples:
```SQL
-- Succeeds
-- temperature (float) and humidity (float) have matching types
SELECT IF(temperature > 85, temperature, humidity) FROM table1;

-- Fails
-- temperature (float) and status (boolean) have mismatched types
SELECT IF(temperature > 85, temperature, status) FROM table1;
```


## 8. Conversion Functions

### 8.1 Conversion Functions
Expand Down
44 changes: 44 additions & 0 deletions src/UserGuide/latest-Table/SQL-Manual/Basis-Function_apache.md
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,50 @@ Returns the first non-null value from the given list of parameters.
coalesce(value1, value2[, ...])
```

### 7.3 IF Expression
The IF expression has two forms: one that specifies only the true value, and another that specifies both the true value and the false value.

| Form | Description | Output Type Restrictions |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------ |
| `IF(condition, true_value)` | If the condition evaluates to true, `true_value` is computed and returned; otherwise, `null` is returned and `true_value` is not evaluated. | — |
| `IF(condition, true_value, false_value)` | If the condition evaluates to true, `true_value` is computed and returned; otherwise, `false_value` is computed and returned. | The data types of `true_value` and `false_value` **must be exactly the same**. Implicit type conversion is not supported. |

> Supported since V2.0.9-beta

**Examples:**

1. Equivalent examples of IF and CASE expressions:
```SQL
-- IF syntax
SELECT
device_id,
temperature,
IF(temperature > 85, 'High Value', 'Low Value')
FROM table1;

-- Equivalent CASE syntax
SELECT
device_id,
temperature,
CASE
WHEN temperature > 85 THEN 'High Value'
ELSE 'Low Value'
END
FROM table1;
```

2. Output type restriction examples:
```SQL
-- Succeeds
-- temperature (float) and humidity (float) have matching types
SELECT IF(temperature > 85, temperature, humidity) FROM table1;

-- Fails
-- temperature (float) and status (boolean) have mismatched types
SELECT IF(temperature > 85, temperature, status) FROM table1;
```


## 8. Conversion Functions

### 8.1 Conversion Functions
Expand Down
45 changes: 45 additions & 0 deletions src/UserGuide/latest-Table/SQL-Manual/Basis-Function_timecho.md
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,51 @@ Returns the first non-null value from the given list of parameters.
coalesce(value1, value2[, ...])
```

### 7.3 IF Expression

The IF expression has two forms: one that specifies only the true value, and another that specifies both the true value and the false value.

| Form | Description | Output Type Restrictions |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------ |
| `IF(condition, true_value)` | If the condition evaluates to true, `true_value` is computed and returned; otherwise, `null` is returned and `true_value` is not evaluated. | — |
| `IF(condition, true_value, false_value)` | If the condition evaluates to true, `true_value` is computed and returned; otherwise, `false_value` is computed and returned. | The data types of `true_value` and `false_value` **must be exactly the same**. Implicit type conversion is not supported. |

> Supported since V2.0.9.1

**Examples:**

1. Equivalent examples of IF and CASE expressions:
```SQL
-- IF syntax
SELECT
device_id,
temperature,
IF(temperature > 85, 'High Value', 'Low Value')
FROM table1;

-- Equivalent CASE syntax
SELECT
device_id,
temperature,
CASE
WHEN temperature > 85 THEN 'High Value'
ELSE 'Low Value'
END
FROM table1;
```

2. Output type restriction examples:
```SQL
-- Succeeds
-- temperature (float) and humidity (float) have matching types
SELECT IF(temperature > 85, temperature, humidity) FROM table1;

-- Fails
-- temperature (float) and status (boolean) have mismatched types
SELECT IF(temperature > 85, temperature, status) FROM table1;
```


## 8. Conversion Functions

### 8.1 Conversion Functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1265,14 +1265,61 @@ SELECT a, b,
coalesce(value1, value2[, ...])
```

### 7.3 IF 表达式

IF 表达式有两种形式:一种仅指定真值(true\_value),另一种同时指定真值和假值(false\_value)。

| 形式 | 说明 | 输出类型限制 |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `if(condition, true_value)` | 若条件(condition)为真,则计算并返回`true_value`;否则返回`null`,且`true_value`不会被计算。 | |
| `if(condition, true_value, false_value)` | 若条件(condition)为真,则计算并返回`true_value`;否则计算并返回`false_value`。 | `true_value`和`false_value`的数据类型​**必须完全一致**​,不支持隐式类型转换。 |

> V 2.0.9-beta 版本起支持

**示例:**

1. IF 表达式和 CASE 表达式等价示例:

```SQL
-- IF 写法
SELECT
device_id,
temperature,
IF(temperature > 85, 'High Value', 'Low Value')
FROM table1;

-- CASE 等价写法
SELECT
device_id,
temperature,
CASE
WHEN temperature > 85 THEN 'High Value'
ELSE 'Low Value'
END
FROM table1;
```

2. 输出类型限制示例:

```SQL
-- 成功
-- temperature(float) 和 humidity(float) 类型一致
select if(temperature > 85, temperature, humidity) from table1

-- 失败
-- temperature(float) 和 status(boolean) 类型不一致
select if(temperature > 85, temperature, status) from table1
```


## 8. 转换函数

### 8.1 转换函数

#### 8.1.1 cast(value AS type) → type

1. 显式地将一个值转换为指定类型。
2. 可以用于将字符串(varchar)转换为数值类型,或数值转换为字符串类型
2. 可以用于将字符串(varchar)转换为数值类型,或数值转换为字符串类型
3. 如果转换失败,将抛出运行时错误。

示例:
Expand Down
49 changes: 49 additions & 0 deletions src/zh/UserGuide/Master/Table/SQL-Manual/Basis-Function_timecho.md
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,55 @@ SELECT a, b,
coalesce(value1, value2[, ...])
```


### 7.3 IF 表达式

IF 表达式有两种形式:一种仅指定真值(true\_value),另一种同时指定真值和假值(false\_value)。

| 形式 | 说明 | 输出类型限制 |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `if(condition, true_value)` | 若条件(condition)为真,则计算并返回`true_value`;否则返回`null`,且`true_value`不会被计算。 | |
| `if(condition, true_value, false_value)` | 若条件(condition)为真,则计算并返回`true_value`;否则计算并返回`false_value`。 | `true_value`和`false_value`的数据类型​**必须完全一致**​,不支持隐式类型转换。 |

> V 2.0.9.1 版本起支持

**示例:**

1. IF 表达式和 CASE 表达式等价示例:

```SQL
-- IF 写法
SELECT
device_id,
temperature,
IF(temperature > 85, 'High Value', 'Low Value')
FROM table1;

-- CASE 等价写法
SELECT
device_id,
temperature,
CASE
WHEN temperature > 85 THEN 'High Value'
ELSE 'Low Value'
END
FROM table1;
```

2. 输出类型限制示例:

```SQL
-- 成功
-- temperature(float) 和 humidity(float) 类型一致
select if(temperature > 85, temperature, humidity) from table1

-- 失败
-- temperature(float) 和 status(boolean) 类型不一致
select if(temperature > 85, temperature, status) from table1
```



## 8. 转换函数

### 8.1 转换函数
Expand Down
47 changes: 47 additions & 0 deletions src/zh/UserGuide/latest-Table/SQL-Manual/Basis-Function_apache.md
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,53 @@ SELECT a, b,
coalesce(value1, value2[, ...])
```

### 7.3 IF 表达式

IF 表达式有两种形式:一种仅指定真值(true\_value),另一种同时指定真值和假值(false\_value)。

| 形式 | 说明 | 输出类型限制 |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `if(condition, true_value)` | 若条件(condition)为真,则计算并返回`true_value`;否则返回`null`,且`true_value`不会被计算。 | |
| `if(condition, true_value, false_value)` | 若条件(condition)为真,则计算并返回`true_value`;否则计算并返回`false_value`。 | `true_value`和`false_value`的数据类型​**必须完全一致**​,不支持隐式类型转换。 |

> V2.0.9-beta 版本起支持

**示例:**

1. IF 表达式和 CASE 表达式等价示例:

```SQL
-- IF 写法
SELECT
device_id,
temperature,
IF(temperature > 85, 'High Value', 'Low Value')
FROM table1;

-- CASE 等价写法
SELECT
device_id,
temperature,
CASE
WHEN temperature > 85 THEN 'High Value'
ELSE 'Low Value'
END
FROM table1;
```

2. 输出类型限制示例:

```SQL
-- 成功
-- temperature(float) 和 humidity(float) 类型一致
select if(temperature > 85, temperature, humidity) from table1

-- 失败
-- temperature(float) 和 status(boolean) 类型不一致
select if(temperature > 85, temperature, status) from table1
```


## 8. 转换函数

### 8.1 转换函数
Expand Down
Loading