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

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 Generation Functions

Function 関数

Description 説明

Example(s)

gen_random_uuiduuid

uuidv4uuid

Generate 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

Generate 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 shift時間順のUUIDを生成します。 タイムスタンプは、UNIXタイムスタンプを使用して、ミリ秒精度+サブ-ミリ秒タイムスタンプ+ランダムで計算されます。 オプショナルパラメータは、指定したintervalで計算されたタイムスタンプをシフトします。

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


注記

The <xref linkend="uuid-ossp"/> module provides additional functions that implement other standard algorithms for generating UUIDs. 《マッチ度[95.419847]》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 Extraction Functions

Function 関数

Description 説明

Example(s)

uuid_extract_timestamp ( uuid ) → timestamp with time zone

Extracts a <type>timestamp with time zone</type> 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. 《マッチ度[88.111888]》この関数はUUIDバージョン1からtimestamp with time zoneを抽出します。 他のバージョンでは、この関数はNULLを返します。 抽出されたタイムスタンプは必ずしもUUIDが生成された時間と正確に同じではありません。これは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 the variant 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. 《マッチ度[86.851211]》この関数は、RFC 4122に記述されている種類のUUIDからバージョンを抽出します。 他の種類については、この関数はNULLを返します。 例えば、gen_random_uuidによって生成されたUUIDに対して、この関数は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>. 《機械翻訳》データタイプUUIDについては、PostgreSQL)の8.12を参照。