@@ -14328,54 +14328,164 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
14328
14328
</indexterm>
14329
14329
14330
14330
<para>
14331
- <productname>PostgreSQL</productname> includes several functions to generate a UUID.
14332
- <synopsis>
14333
- <function>gen_random_uuid</function> () <returnvalue>uuid</returnvalue>
14334
- <function>uuidv4</function> () <returnvalue>uuid</returnvalue>
14335
- </synopsis>
14336
- These functions return a version 4 (random) UUID.
14337
- <synopsis>
14338
- <function>uuidv7</function> (<optional> <parameter>shift</parameter> <type>interval</type> </optional>) <returnvalue>uuid</returnvalue>
14339
- </synopsis>
14340
- This function returns a version 7 UUID (UNIX timestamp with millisecond
14341
- precision + sub-millisecond timestamp + random). This function can accept
14342
- optional <parameter>shift</parameter> parameter of type <type>interval</type>
14343
- which shift internal timestamp by the given interval.
14331
+ <xref linkend="func_uuid_gen_table"/> shows the <productname>PostgreSQL</productname>
14332
+ functions that can be used to generate UUIDs.
14344
14333
</para>
14345
14334
14346
- <para>
14347
- The <xref linkend="uuid-ossp"/> module provides additional functions that
14348
- implement other standard algorithms for generating UUIDs.
14349
- </para>
14335
+ <table id="func_uuid_gen_table">
14336
+ <title><acronym>UUID</acronym> Generation Functions</title>
14337
+ <tgroup cols="1">
14338
+ <thead>
14339
+ <row>
14340
+ <entry role="func_table_entry">
14341
+ <para role="func_signature">
14342
+ Function
14343
+ </para>
14344
+ <para>
14345
+ Description
14346
+ </para>
14347
+ <para>
14348
+ Example(s)
14349
+ </para>
14350
+ </entry>
14351
+ </row>
14352
+ </thead>
14350
14353
14351
- <para>
14352
- There are also functions to extract data from UUIDs:
14353
- <synopsis>
14354
- <function>uuid_extract_timestamp</function> (uuid) <returnvalue>timestamp with time zone</returnvalue>
14355
- </synopsis>
14356
- This function extracts a <type>timestamp with time zone</type> from UUID
14357
- version 1 and 7. For other versions, this function returns null. Note that
14358
- the extracted timestamp is not necessarily exactly equal to the time the
14359
- UUID was generated; this depends on the implementation that generated the
14360
- UUID.
14361
- </para>
14354
+ <tbody>
14355
+ <row>
14356
+ <entry role="func_table_entry">
14357
+ <para role="func_signature">
14358
+ <type>gen_random_uuid</type>
14359
+ <returnvalue>uuid</returnvalue>
14360
+ </para>
14361
+ <para role="func_signature">
14362
+ <type>uuidv4</type>
14363
+ <returnvalue>uuid</returnvalue>
14364
+ </para>
14365
+ <para>
14366
+ Generate a version 4 (random) UUID.
14367
+ </para>
14368
+ <para>
14369
+ <literal>gen_random_uuid()</literal>
14370
+ <returnvalue>5b30857f-0bfa-48b5-ac0b-5c64e28078d1</returnvalue>
14371
+ </para>
14372
+ <para>
14373
+ <literal>uuidv4()</literal>
14374
+ <returnvalue>b42410ee-132f-42ee-9e4f-09a6485c95b8</returnvalue>
14375
+ </para>
14376
+ </entry>
14377
+ </row>
14378
+ <row>
14379
+ <entry role="func_table_entry">
14380
+ <para role="func_signature">
14381
+ <type>uuidv7</type>
14382
+ ( <optional> <parameter>shift</parameter> <type>interval</type> </optional> )
14383
+ <returnvalue>uuid</returnvalue>
14384
+ </para>
14385
+ <para>
14386
+ Generate a version 7 (time-ordered) UUID. The timestamp is computed using UNIX timestamp
14387
+ with millisecond precision + sub-millisecond timestamp + random. The optional parameter
14388
+ <parameter>shift</parameter> will shift the computed timestamp by the given <type>interval</type>.
14389
+ </para>
14390
+ <para>
14391
+ <literal>uuidv7()</literal>
14392
+ <returnvalue>019535d9-3df7-79fb-b466-fa907fa17f9e</returnvalue>
14393
+ </para>
14394
+ </entry>
14395
+ </row>
14396
+ </tbody>
14397
+ </tgroup>
14398
+ </table>
14399
+
14400
+ <note>
14401
+ <para>
14402
+ The <xref linkend="uuid-ossp"/> module provides additional functions that
14403
+ implement other standard algorithms for generating UUIDs.
14404
+ </para>
14405
+ </note>
14362
14406
14363
14407
<para>
14364
- <synopsis>
14365
- <function>uuid_extract_version</function> (uuid) <returnvalue>smallint</returnvalue>
14366
- </synopsis>
14367
- This function extracts the version from a UUID of the variant described by
14368
- <ulink url="https://datatracker.ietf.org/doc/html/rfc9562">RFC 9562</ulink>. For
14369
- other variants, this function returns null. For example, for a UUID
14370
- generated by <function>gen_random_uuid</function>, this function will
14371
- return 4.
14408
+ <xref linkend="func_uuid_extract_table"/> shows the <productname>PostgreSQL</productname>
14409
+ functions that can be used to extract information from UUIDs.
14372
14410
</para>
14373
14411
14412
+ <table id="func_uuid_extract_table">
14413
+ <title><acronym>UUID</acronym> Extraction Functions</title>
14414
+ <tgroup cols="1">
14415
+ <thead>
14416
+ <row>
14417
+ <entry role="func_table_entry">
14418
+ <para role="func_signature">
14419
+ Function
14420
+ </para>
14421
+ <para>
14422
+ Description
14423
+ </para>
14424
+ <para>
14425
+ Example(s)
14426
+ </para>
14427
+ </entry>
14428
+ </row>
14429
+ </thead>
14430
+
14431
+ <tbody>
14432
+ <row>
14433
+ <entry role="func_table_entry">
14434
+ <para role="func_signature">
14435
+ <type>uuid_extract_timestamp</type>
14436
+ ( <type>uuid</type> )
14437
+ <returnvalue>timestamp with time zone</returnvalue>
14438
+ </para>
14439
+ <para>
14440
+ Extracts a <type>timestamp with time zone</type> from UUID
14441
+ version 1 and 7. For other versions, this function returns null. Note that
14442
+ the extracted timestamp is not necessarily exactly equal to the time the
14443
+ UUID was generated; this depends on the implementation that generated the
14444
+ UUID.
14445
+ </para>
14446
+ <para>
14447
+ <literal>uuid_extract_timestamp('019535d9-3df7-79fb-b466-fa907fa17f9e'::uuid)</literal>
14448
+ <returnvalue>2025-02-23 21:46:24.503-05</returnvalue>
14449
+ </para>
14450
+ </entry>
14451
+ </row>
14452
+ <row>
14453
+ <entry role="func_table_entry">
14454
+ <para role="func_signature">
14455
+ <type>uuid_extract_version</type>
14456
+ ( <type>uuid</type> )
14457
+ <returnvalue>smallint</returnvalue>
14458
+ </para>
14459
+ <para>
14460
+ Extracts the version from a UUID of the variant described by
14461
+ <ulink url="https://datatracker.ietf.org/doc/html/rfc9562">RFC 9562</ulink>. For
14462
+ other variants, this function returns null. For example, for a UUID
14463
+ generated by <function>gen_random_uuid</function>, this function will
14464
+ return 4.
14465
+ </para>
14466
+ <para>
14467
+ <literal>uuid_extract_version('41db1265-8bc1-4ab3-992f-885799a4af1d'::uuid)</literal>
14468
+ <returnvalue>4</returnvalue>
14469
+ </para>
14470
+ <para>
14471
+ <literal>uuid_extract_version('019535d9-3df7-79fb-b466-fa907fa17f9e'::uuid)</literal>
14472
+ <returnvalue>7</returnvalue>
14473
+ </para>
14474
+ </entry>
14475
+ </row>
14476
+ </tbody>
14477
+ </tgroup>
14478
+ </table>
14479
+
14374
14480
<para>
14375
14481
<productname>PostgreSQL</productname> also provides the usual comparison
14376
14482
operators shown in <xref linkend="functions-comparison-op-table"/> for
14377
14483
UUIDs.
14378
14484
</para>
14485
+ <para>
14486
+ See <xref linkend="datatype-uuid"/> for details on the data type
14487
+ <type>uuid</type> in <productname>PostgreSQL</productname>.
14488
+ </para>
14379
14489
</sect1>
14380
14490
14381
14491
<sect1 id="functions-xml">
0 commit comments