バージョンごとのドキュメント一覧

9.14. UUID関数 #

<title>UUID Functions</title>

<xref linkend="func_uuid_gen_table"/> shows the <productname>PostgreSQL</productname> functions that can be used to generate UUIDs. 表 9.45は、UUIDの生成に使用できるPostgreSQLの関数を示しています。

表9.45 UUID生成関数

<title><acronym>UUID</acronym> Generation Functions</title>

Function 関数

Description 説明

Example(s)

gen_random_uuid ( ) → uuid

uuidv4 ( ) → uuid

Generates a version 4 (random) UUID バージョン4(ランダム)のUUIDを生成します。

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

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

uuidv7 ( [ shift interval ] ) → uuid

Generates a version 7 (time-ordered) UUID. The timestamp is computed using UNIX timestamp with millisecond precision + sub-millisecond timestamp + random. The optional parameter <parameter>shift</parameter> will shift the computed timestamp by the given <type>interval</type>. バージョン7(時間順)のUUIDを生成します。 タイムスタンプは、ミリ秒精度のUNIXタイムスタンプ+サブミリ秒のタイムスタンプ+ランダム値を使用して計算されます。 オプションのパラメータshiftは、計算されたタイムスタンプを指定されたintervalだけシフトします。

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


注記

The <xref linkend="uuid-ossp"/> module provides additional functions that implement other standard algorithms for generating UUIDs. uuid-osspモジュールは、UUIDを生成するための他の標準アルゴリズムを実装した追加の関数を提供します。

<xref linkend="func_uuid_extract_table"/> shows the <productname>PostgreSQL</productname> functions that can be used to extract information from UUIDs. 表 9.46は、UUIDから情報を抽出するために使用できるPostgreSQL関数を示しています。

表9.46 UUID抽出関数

<title><acronym>UUID</acronym> Extraction Functions</title>

Function 関数

Description 説明

Example(s)

uuid_extract_timestamp ( uuid ) → timestamp with time zone

Extracts a <type>timestamp with time zone</type> from a UUID of version 1 or 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のバージョン1または7からtimestamp with time zoneを抽出します。 他のバージョンでは、この関数はNULLを返します。 抽出されたタイムスタンプは必ずしもUUIDが生成された時間と正確に同じではありません。 これは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 one of the variants described by <ulink url="https://datatracker.ietf.org/doc/html/rfc9562">RFC 9562</ulink>. For other variants, this function returns null. For example, for a UUID generated by <function>gen_random_uuid()</function>, this function will return 4. この関数は、RFC 9562で説明されている種類のUUIDからバージョンを抽出します。 他の種類については、この関数はNULLを返します。 例えば、gen_random_uuid()によって生成されたUUIDに対して、この関数は4を返します。

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

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


<productname>PostgreSQL</productname> also provides the usual comparison operators shown in <xref linkend="functions-comparison-op-table"/> for UUIDs. PostgreSQL表 9.1で示すUUIDのための通常の比較演算子を提供しています。

See <xref linkend="datatype-uuid"/> for details on the data type <type>uuid</type> in <productname>PostgreSQL</productname>. PostgreSQLUUIDデータ型の詳細は8.12を参照してください。