PostgreSQL 生成 UUID

PostgreSQL UUID About 1,483 words

uuid 插件

PostgreSQL内置了"uuid-ossp"插件,用于生产UUID

postgres=# \dx+ uuid-ossp
   Objects in extension "uuid-ossp"
          Object description
--------------------------------------
 function uuid_generate_v1()
 function uuid_generate_v1mc()
 function uuid_generate_v3(uuid,text)
 function uuid_generate_v4()
 function uuid_generate_v5(uuid,text)
 function uuid_nil()
 function uuid_ns_dns()
 function uuid_ns_oid()
 function uuid_ns_url()
 function uuid_ns_x500()
(10 rows)

创建插件

create extension if not exists "uuid-ossp";

内置函数

PostgreSQL 12起内置了gen_random_uuid()函数,改函数提供的是V4版本的UUID

SQL

postgres=# select gen_random_uuid() as v4, uuid_generate_v1(), uuid_generate_v1mc(), uuid_generate_v3(uuid_generate_v1(), 'my-name'), uuid_generate_v4(), uuid_generate_v5(uuid_generate_v1(), 'my-name');
                  v4                  |           uuid_generate_v1           |          uuid_generate_v1mc          |           uuid_generate_v3           |           uuid_generate_v4           |           uuid_generate_v5
--------------------------------------+--------------------------------------+--------------------------------------+--------------------------------------+--------------------------------------+--------------------------------------
 34184410-a31f-4c0f-8c34-ad02a15afc74 | 2330d2d8-1cc1-11ef-8d8c-de78632ca3f0 | 2330d4b8-1cc1-11ef-8d8c-e334fa7a6367 | e0d413e6-08fb-3767-a82b-ea0535304517 | 2ff69480-893a-4524-a8b5-51d4d5ec6f42 | 60a1d88c-4279-56b1-8e80-37f7980672d2
(1 row)
Views: 343 · Posted: 2024-06-12

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Today On History
Browsing Refresh