uuid_extract_timestamp()

从UUID中提取时间戳的函数

uuid_extract_timestamp() 是一个用于从版本1 UUID 中提取时间戳的系统函数。

uuid_extract_timestamp()PostgreSQL 17 中添加。

用法

uuid_extract_timestamp ( uuid ) → timestamp with time zone

如果提供的 UUID 不是版本 1 (或从 PostgreSQL 18 开始) 版本 7,则返回 NULL

变更历史

示例

使用 uuid-ossp 扩展中的 uuid_generate_v1() 函数来演示 uuid_extract_timestamp() 的基本用法

postgres=# SELECT uuid_extract_timestamp( uuid_generate_v1()  );
    uuid_extract_timestamp     
-------------------------------
 2024-03-20 15:25:01.989091+09
(1 row)

对于版本 17 以外的 UUID 版本,将返回 NULL

postgres=# SELECT uuid_extract_timestamp( gen_random_uuid() ) IS NULL;
 ?column? 
----------
 t
(1 row)

postgres=# SELECT uuid_extract_timestamp( uuid_generate_v3 ( uuid_ns_oid(), 'foo') ) IS NULL;
 ?column? 
----------
 t
(1 row)

分类

系统函数, UUID

另请参阅

uuid_extract_version(), uuid-ossp

反馈

提交任何关于“uuid_extract_timestamp()”的评论、建议或更正 在此处