Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Request a Demo
9.14. UUID Functions
Prev UpChapter 9. Functions and OperatorsHome Next

9.14. UUID Functions#

Table 9.45 shows thePostgreSQL functions that can be used to generate UUIDs.

Table 9.45. UUID Generation Functions

Function

Description

Example(s)

gen_random_uuiduuid

uuidv4uuid

Generate a version 4 (random) UUID.

gen_random_uuid()5b30857f-0bfa-48b5-ac0b-5c64e28078d1

uuidv4()b42410ee-132f-42ee-9e4f-09a6485c95b8

uuidv7 ( [shiftinterval] ) →uuid

Generate a version 7 (time-ordered) UUID. The timestamp is computed using UNIX timestamp with millisecond precision + sub-millisecond timestamp + random. The optional parametershift will shift the computed timestamp by the giveninterval.

uuidv7()019535d9-3df7-79fb-b466-fa907fa17f9e


Note

Theuuid-ossp module provides additional functions that implement other standard algorithms for generating UUIDs.

Table 9.46 shows thePostgreSQL functions that can be used to extract information from UUIDs.

Table 9.46. UUID Extraction Functions

Function

Description

Example(s)

uuid_extract_timestamp (uuid ) →timestamp with time zone

Extracts atimestamp with time zone from UUID version 1 and 7. For other versions, this function returns null. Note that the extracted timestamp is not necessarily exactly equal to the time the UUID was generated; this depends on the implementation that generated the UUID.

uuid_extract_timestamp('019535d9-3df7-79fb-b466-​fa907fa17f9e'::uuid)2025-02-23 21:46:24.503-05

uuid_extract_version (uuid ) →smallint

Extracts the version from a UUID of the variant described byRFC 9562. For other variants, this function returns null. For example, for a UUID generated bygen_random_uuid, this function will return 4.

uuid_extract_version('41db1265-8bc1-4ab3-992f-​885799a4af1d'::uuid)4

uuid_extract_version('019535d9-3df7-79fb-b466-​fa907fa17f9e'::uuid)7


PostgreSQL also provides the usual comparison operators shown inTable 9.1 for UUIDs.

SeeSection 8.12 for details on the data typeuuid inPostgreSQL.


Prev Up Next
9.13. Text Search Functions and Operators Home 9.15. XML Functions
epubpdf
Go to PostgreSQL 18
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp