Skip to content

Commit

Permalink
reference/sql: update functions and operators (#1729)
Browse files Browse the repository at this point in the history
* reference/sql: update functions and operators

* improve wording
  • Loading branch information
yikeke committed Aug 12, 2019
1 parent d6e5e35 commit 097b45b
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 136 deletions.
Expand Up @@ -5,7 +5,7 @@ category: reference


# 位函数和操作符 # 位函数和操作符


TiDB 中位函数和操作符的使用方法与 MySQL 基本一致,详情参见: [Bit Functions and Operators](https://dev.mysql.com/doc/refman/5.7/en/bit-functions.html) TiDB 支持使用 MySQL 5.7 中提供的所有[位函数和操作符](https://dev.mysql.com/doc/refman/5.7/en/bit-functions.html)


**位函数和操作符表** **位函数和操作符表**


Expand Down
Expand Up @@ -5,7 +5,7 @@ category: reference


# Cast 函数和操作符 # Cast 函数和操作符


Cast 函数和操作符用于将某种数据类型的值转换为另一种数据类型。TiDB 中该函数和操作符的使用方法与 MySQL基本一致,详情参见: [Cast Functions and Operators](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html). Cast 函数和操作符用于将某种数据类型的值转换为另一种数据类型。TiDB 支持使用 MySQL 5.7 中提供的所有 [Cast 函数和操作符](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html)


## Cast 函数和操作符表 ## Cast 函数和操作符表


Expand Down
Expand Up @@ -5,6 +5,8 @@ category: reference


# 控制流程函数 # 控制流程函数


TiDB 支持使用 MySQL 5.7 中提供的所有[控制流程函数](https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html)

| 函数名 | 功能描述 | | 函数名 | 功能描述 |
|:--------------------------------------------------------------------------------------------------|:----------------------------------| |:--------------------------------------------------------------------------------------------------|:----------------------------------|
| [`CASE`](https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case) | Case 操作符 | | [`CASE`](https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case) | Case 操作符 |
Expand Down
Expand Up @@ -5,7 +5,7 @@ category: reference


# 日期和时间函数 # 日期和时间函数


TiDB 中日期和时间函数的使用方法与 MySQL 基本一致,详情参见: [Date and Time Functions](https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html). TiDB 支持使用 MySQL 5.7 中提供的所有[日期和时间函数](https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html)


## 日期时间函数表 ## 日期时间函数表


Expand Down
Expand Up @@ -5,6 +5,10 @@ category: reference


# 加密和压缩函数 # 加密和压缩函数


TiDB 支持使用 MySQL 5.7 中提供的大部分[加密和压缩函数](https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html)

## 支持的函数

| 函数名 | 功能描述 | | 函数名 | 功能描述 |
|:-----------|:----------------------------| |:-----------|:----------------------------|
| [`MD5()`](https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_md5)                                                             | 计算字符串的 MD5 校验和       | | [`MD5()`](https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_md5)                                                             | 计算字符串的 MD5 校验和       |
Expand All @@ -26,3 +30,9 @@ category: reference
| [`ASYMMETRIC_ENCRYPT()`](https://dev.mysql.com/doc/refman/5.7/en/enterprise-encryption-functions.html#function_asymmetric-encrypt) | 使用公钥或私钥加密明文 | | [`ASYMMETRIC_ENCRYPT()`](https://dev.mysql.com/doc/refman/5.7/en/enterprise-encryption-functions.html#function_asymmetric-encrypt) | 使用公钥或私钥加密明文 |
| [`ASYMMETRIC_SIGN()`](https://dev.mysql.com/doc/refman/5.7/en/enterprise-encryption-functions.html#function_asymmetric-sign) | 从摘要创建签名 | | [`ASYMMETRIC_SIGN()`](https://dev.mysql.com/doc/refman/5.7/en/enterprise-encryption-functions.html#function_asymmetric-sign) | 从摘要创建签名 |
| [`ASYMMETRIC_VERIFY()`](https://dev.mysql.com/doc/refman/5.7/en/enterprise-encryption-functions.html#function_asymmetric-verify) | 验证签名字符串是否匹配摘要字符串 | | [`ASYMMETRIC_VERIFY()`](https://dev.mysql.com/doc/refman/5.7/en/enterprise-encryption-functions.html#function_asymmetric-verify) | 验证签名字符串是否匹配摘要字符串 |

## 不支持的函数

* `DES_DECRYPT()``DES_ENCRYPT()``OLD_PASSWORD()``ENCRYPT()`:这些函数在 MySQL 5.7 中被废弃,并且已在 MySQL 8.0 中移除。
* `VALIDATE_PASSWORD_STRENGTH()` 函数。
* 只在 MySQL 企业版中支持的函数。见 [Issue #2632](https://github.com/pingcap/tidb/issues/2632)
12 changes: 10 additions & 2 deletions dev/reference/sql/functions-and-operators/information-functions.md
Expand Up @@ -5,20 +5,28 @@ category: reference


# 信息函数 # 信息函数


TiDB 中信息函数的使用方法与 MySQL 基本一致,详情参见:[Information Functions](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html) TiDB 支持使用 MySQL 5.7 中提供的大部分[信息函数](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html)


## 信息函数表 ## 支持的函数


| 函数名 | 功能描述 | | 函数名 | 功能描述 |
| ------ | ---------------------------------------- | | ------ | ---------------------------------------- |
| [`BENCHMARK()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_benchmark) | 循环执行一个表达式 |
| [`CONNECTION_ID()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_connection-id) | 返回当前连接的连接 ID (线程 ID) | | [`CONNECTION_ID()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_connection-id) | 返回当前连接的连接 ID (线程 ID) |
| [`CURRENT_USER()`, `CURRENT_USER`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_current-user) | 返回当前用户的用户名和主机名 | | [`CURRENT_USER()`, `CURRENT_USER`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_current-user) | 返回当前用户的用户名和主机名 |
| [`DATABASE()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_database) | 返回默认(当前)的数据库名 | | [`DATABASE()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_database) | 返回默认(当前)的数据库名 |
| [`FOUND_ROWS()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_found-rows) | 该函数返回对于一个包含 LIMIT 的 SELECT 查询语句,在不包含 LIMIT 的情况下回返回的记录数 | | [`FOUND_ROWS()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_found-rows) | 该函数返回对于一个包含 LIMIT 的 SELECT 查询语句,在不包含 LIMIT 的情况下回返回的记录数 |
| [`LAST_INSERT_ID()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_last-insert-id) | 返回最后一条 INSERT 语句中自增列的值 | | [`LAST_INSERT_ID()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_last-insert-id) | 返回最后一条 INSERT 语句中自增列的值 |
| [`ROW_COUNT()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_row-count) | 影响的行数 |
| [`SCHEMA()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_schema) | 与 DATABASE() 同义 | | [`SCHEMA()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_schema) | 与 DATABASE() 同义 |
| [`SESSION_USER()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_session-user) | 与 USER() 同义 | | [`SESSION_USER()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_session-user) | 与 USER() 同义 |
| [`SYSTEM_USER()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_system-user) | 与 USER() 同义 | | [`SYSTEM_USER()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_system-user) | 与 USER() 同义 |
| [`USER()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_user) | 返回客户端提供的用户名和主机名 | | [`USER()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_user) | 返回客户端提供的用户名和主机名 |
| [`VERSION()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_version) | 返回当前 MySQL 服务器的版本信息 | | [`VERSION()`](https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_version) | 返回当前 MySQL 服务器的版本信息 |
| `TIDB_VERSION()` | 返回当前 TiDB 服务器的版本信息 | | `TIDB_VERSION()` | 返回当前 TiDB 服务器的版本信息 |

## 不支持的函数

* `CHARSET()`
* `COERCIBILITY()`
* `COLLATION()`
Expand Up @@ -5,12 +5,14 @@ category: reference


# 其他函数 # 其他函数


TiDB 支持使用 MySQL 5.7 中提供的大部分[其他函数](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html)

## 支持的函数

| 函数名 | 功能描述 | | 函数名 | 功能描述 |
|:------|:-----------| |:------|:-----------|
| [`ANY_VALUE()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_any-value) |`ONLY_FULL_GROUP_BY` 模式下,防止带有 `GROUP BY` 的语句报错 | | [`ANY_VALUE()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_any-value) |`ONLY_FULL_GROUP_BY` 模式下,防止带有 `GROUP BY` 的语句报错 |
| [`SLEEP()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_sleep) | 休眠指定秒数 | | [`DEFAULT()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_default) | 返回表的某一列的默认值 |
| [`UUID()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_uuid) | 返回通用唯一识别码 (UUID) |
| [`VALUES()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values) | 定义 `INSERT` 过程中要用到的值 |
| [`INET_ATON()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_inet-aton) | 将 IP 地址转换为数值 | | [`INET_ATON()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_inet-aton) | 将 IP 地址转换为数值 |
| [`INET_NTOA()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_inet-ntoa) | 将数值转换为 IP 地址 | | [`INET_NTOA()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_inet-ntoa) | 将数值转换为 IP 地址 |
| [`INET6_ATON()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_inet6-aton) | 将 IPv6 地址转换为数值   | | [`INET6_ATON()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_inet6-aton) | 将 IPv6 地址转换为数值   |
Expand All @@ -19,5 +21,14 @@ category: reference
| [`IS_IPV4_COMPAT()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_is-ipv4-compat) | 判断参数是否为兼容 IPv4 的地址 | | [`IS_IPV4_COMPAT()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_is-ipv4-compat) | 判断参数是否为兼容 IPv4 的地址 |
| [`IS_IPV4_MAPPED()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_is-ipv4-mapped) | 判断参数是否为 IPv4 映射的地址 | | [`IS_IPV4_MAPPED()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_is-ipv4-mapped) | 判断参数是否为 IPv4 映射的地址 |
| [`IS_IPV6()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_is-ipv6) | 判断参数是否为 IPv6 地址 | | [`IS_IPV6()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_is-ipv6) | 判断参数是否为 IPv6 地址 |
| [`GET_LOCK()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock)   | 获取命名锁,TiDB     出于兼容性支持这个函数,实际上不会做任何操作,这点和 MySQL 有区别 | | [`NAME_CONST()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_name-const) | 可以用于重命名列名 |
| [`RELEASE_LOCK()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_release-lock) | 释放命名锁 | | [`SLEEP()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_sleep) | 让语句暂停执行几秒时间 |
| [`UUID()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_uuid) | 返回一个通用唯一识别码 (UUID) |
| [`VALUES()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values) | 定义 `INSERT` 语句使用的值 |

## 不支持的函数

| [`GET_LOCK()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock) | 获取命名锁,详见 [TiDB #10929](https://github.com/pingcap/tidb/issues/10929) |
| [`RELEASE_LOCK()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_release-lock) | 释放命名锁,详见 [TiDB #10929](https://github.com/pingcap/tidb/issues/10929) |
| [`UUID_SHORT()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_uuid-short) | 基于特定假设提供唯一的 UUID,目前这些假设在 TiDB 中不存在,详见 [TiDB #4620](https://github.com/pingcap/tidb/issues/4620) |
| [`MASTER_WAIT_POS()`](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_master-pos-wait) | 与 MySQL 同步相关 |
Expand Up @@ -5,6 +5,8 @@ category: reference


# 数值函数与操作符 # 数值函数与操作符


TiDB 支持使用 MySQL 5.7 中提供的所有[数值函数与操作符](https://dev.mysql.com/doc/refman/5.7/en/numeric-functions.html)

## 算术操作符 ## 算术操作符


| 操作符名 | 功能描述 | | 操作符名 | 功能描述 |
Expand Down

0 comments on commit 097b45b

Please sign in to comment.