-
Notifications
You must be signed in to change notification settings - Fork 709
Add new UUID functions #22234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dveeden
wants to merge
9
commits into
pingcap:master
Choose a base branch
from
dveeden:new_uuid_func
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add new UUID functions #22234
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2200022
Add new UUID functions
dveeden 290fa8c
Update functions-and-operators/miscellaneous-functions.md
dveeden a3fb9ec
Apply suggestions from code review
dveeden 018ca9a
Fix order
dveeden 582bbac
Various updates
dveeden 5d32c85
Updates from Gemini review
dveeden 7cc95d9
Add info about UUID as expression default
dveeden a38d1dc
Add info about generated columns
dveeden 43fa4a7
Add pushdown info
dveeden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,15 +20,19 @@ TiDB supports most of the [miscellaneous functions](https://dev.mysql.com/doc/re | |
| | [`INET_NTOA()`](#inet_ntoa) | Return the IP address from a numeric value | | ||
| | [`INET6_ATON()`](#inet6_aton) | Return the numeric value of an IPv6 address | | ||
| | [`INET6_NTOA()`](#inet6_ntoa) | Return the IPv6 address from a numeric value | | ||
| | [`IS_IPV4()`](#is_ipv4) | Whether argument is an IPv4 address | | ||
| | [`IS_IPV4_COMPAT()`](#is_ipv4_compat) | Whether argument is an IPv4-compatible address | | ||
| | [`IS_IPV4_MAPPED()`](#is_ipv4_mapped) | Whether argument is an IPv4-mapped address | | ||
| | [`IS_IPV4()`](#is_ipv4) | Whether argument is an IPv4 address | | ||
| | [`IS_IPV6()`](#is_ipv6) | Whether argument is an IPv6 address | | ||
| | [`IS_UUID()`](#is_uuid) | Whether argument is an UUID | | ||
| | [`NAME_CONST()`](#name_const) | Can be used to rename a column name | | ||
| | [`SLEEP()`](#sleep) | Sleep for a number of seconds. Note that for [{{{ .starter }}}](https://docs.pingcap.com/tidbcloud/select-cluster-tier#starter) and [{{{ .essential }}}](https://docs.pingcap.com/tidbcloud/select-cluster-tier#essential) clusters, the `SLEEP()` function has a limitation wherein it can only support a maximum sleep time of 300 seconds. | | ||
| | [`UUID()`](#uuid) | Return a Universal Unique Identifier (UUID) | | ||
| | [`UUID_TIMESTAMP()`](#uuid_timestamp) | Return the timestamp of a UUID | | ||
| | [`UUID_TO_BIN()`](#uuid_to_bin) | Convert UUID from text format to binary format | | ||
| | [`UUID_V4()`](#uuid_v4) | Return a v4 Universal Unique Identifier (UUID) | | ||
| | [`UUID_V7()`](#uuid_v7) | Return a v7 Universal Unique Identifier (UUID) | | ||
| | [`UUID_VERSION()`](#uuid_version) | Return the UUID version of a UUID | | ||
| | [`UUID()`](#uuid) | Return a v1 Universal Unique Identifier (UUID) | | ||
|
dveeden marked this conversation as resolved.
Outdated
|
||
| | [`VALUES()`](#values) | Defines the values to be used during an INSERT | | ||
|
|
||
| ### ANY_VALUE() | ||
|
|
@@ -361,9 +365,117 @@ SELECT SLEEP(1.5); | |
| 1 row in set (1.50 sec) | ||
| ``` | ||
|
|
||
| ### UUID_VERSION() | ||
|
|
||
| The `UUID_VERSION()` function returns the UUID version of the UUID as defined in [RFC 9562](https://datatracker.ietf.org/doc/html/rfc9562). | ||
|
dveeden marked this conversation as resolved.
Outdated
|
||
|
|
||
| The following example shows a version 1 UUID. | ||
|
dveeden marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```sql | ||
| SELECT UUID_VERSION('7d31138f-e0ee-11f0-a2db-86f42566cd2c'); | ||
| ``` | ||
|
|
||
| ``` | ||
| +------------------------------------------------------+ | ||
| | UUID_VERSION('7d31138f-e0ee-11f0-a2db-86f42566cd2c') | | ||
| +------------------------------------------------------+ | ||
| | 1 | | ||
| +------------------------------------------------------+ | ||
| 1 row in set (0.001 sec) | ||
| ``` | ||
|
|
||
| The following example shows a version 7 UUID. | ||
|
dveeden marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```sql | ||
| SELECT UUID_VERSION('019b516b-8ef7-7d74-81e6-9b860112409a'); | ||
| ``` | ||
|
|
||
| ``` | ||
| +------------------------------------------------------+ | ||
| | UUID_VERSION('019b516b-8ef7-7d74-81e6-9b860112409a') | | ||
| +------------------------------------------------------+ | ||
| | 7 | | ||
| +------------------------------------------------------+ | ||
| 1 row in set (0.001 sec) | ||
| ``` | ||
|
|
||
| ### UUID_V4() | ||
|
|
||
| The `UUID_V4()` function returns a universally unique identifier (UUID) version 4 as defined in [RFC 9562](https://datatracker.ietf.org/doc/html/rfc9562). | ||
|
|
||
| ```sql | ||
| SELECT UUID_V4(); | ||
| ``` | ||
|
|
||
| ``` | ||
| +--------------------------------------+ | ||
| | UUID_V4() | | ||
| +--------------------------------------+ | ||
| | e76d4b18-7f8d-418d-8f9b-f42b4f1d803b | | ||
| +--------------------------------------+ | ||
| 1 row in set (0.001 sec) | ||
| ``` | ||
|
|
||
| See also [Best practices for UUID](/best-practices/uuid.md). | ||
|
|
||
| ### UUID_V7() | ||
|
|
||
| The `UUID_V4()` function returns a universally unique identifier (UUID) version 7 as defined in [RFC 9562](https://datatracker.ietf.org/doc/html/rfc9562). | ||
|
dveeden marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```sql | ||
| SELECT UUID_V7(); | ||
| ``` | ||
|
|
||
| ``` | ||
| +--------------------------------------+ | ||
| | UUID_V7() | | ||
| +--------------------------------------+ | ||
| | 019b5171-c5e4-743a-b192-96fbb28d1d7e | | ||
| +--------------------------------------+ | ||
| 1 row in set (0.001 sec) | ||
| ``` | ||
|
|
||
| See also [Best practices for UUID](/best-practices/uuid.md). | ||
|
|
||
| ### UUID_TIMESTAMP() | ||
|
|
||
| The `UUID_TIMESTAMP()` function extracts the timestamp that is stored in a UUID for the UUID versions that include a timestamp and returns this as a UNIX timestamp. | ||
|
dveeden marked this conversation as resolved.
Outdated
|
||
|
|
||
| Only UUIDv1, UUIDv6 and UUIDv7 do store a timestamp. For other UUID versions this function will return `NULL`. | ||
|
dveeden marked this conversation as resolved.
Outdated
|
||
|
|
||
| The example below extracts the timestamp from a UUID. | ||
|
|
||
| ```sql | ||
| SELECT UUID_TIMESTAMP('019b5171-c5e4-743a-b192-96fbb28d1d7e'); | ||
| ``` | ||
|
|
||
| ``` | ||
| +--------------------------------------------------------+ | ||
| | UUID_TIMESTAMP('019b5171-c5e4-743a-b192-96fbb28d1d7e') | | ||
| +--------------------------------------------------------+ | ||
| | 1766597969.380000 | | ||
| +--------------------------------------------------------+ | ||
| 1 row in set (0.001 sec) | ||
| ``` | ||
|
|
||
| The resulting UNIX timestamp can be used directly with [`FROM_UNIXTIME()`](/functions-and-operators/date-and-time-functions.md) to get a timestamp. | ||
|
|
||
| ```sql | ||
| SELECT FROM_UNIXTIME(1766597969.380000); | ||
| ``` | ||
|
|
||
| ``` | ||
| +----------------------------------+ | ||
| | FROM_UNIXTIME(1766597969.380000) | | ||
| +----------------------------------+ | ||
| | 2025-12-24 18:39:29.380000 | | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Working late on Christmas eve? ;)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎄🎄🎄 |
||
| +----------------------------------+ | ||
| 1 row in set (0.001 sec) | ||
| ``` | ||
|
|
||
| ### UUID() | ||
|
|
||
| The `UUID()` function returns a universally unique identifier (UUID) version 1 as defined in [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122). | ||
| The `UUID()` function returns a universally unique identifier (UUID) version 1 as defined in [RFC 9562](https://datatracker.ietf.org/doc/html/rfc9562). | ||
|
|
||
| ```sql | ||
| SELECT UUID(); | ||
|
|
@@ -417,4 +529,4 @@ TABLE t1; | |
|
|
||
| | Name | Description | | ||
| |:------------|:-----------------------------------------------------------------------------------------------| | ||
| | [`UUID_SHORT()`](https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-short) | Provides a UUID that is unique given certain assumptions not present in TiDB [TiDB #4620](https://github.com/pingcap/tidb/issues/4620) | | ||
| | [`UUID_SHORT()`](https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-short) | Provides a UUID that is unique given certain assumptions not present in TiDB [TiDB #4620](https://github.com/pingcap/tidb/issues/4620) | | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.