/
Ao
/
MaxReport
Обзор
Документация
Войти
/
Ao
/
MaxReport
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
pgsql/doc/src/sgml/html/functions-uuid.html
102 строки
8 KB
AoAnima
first_commit
13 июл 2026, 17:47
13 июл 2026, 17:47
f1a670a
Код
Авторство
О чём код?
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>9.14. UUID Functions</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="functions-textsearch.html" title="9.13. Text Search Functions and Operators" /><link rel="next" href="functions-xml.html" title="9.15. XML Functions" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">9.14. UUID Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-textsearch.html" title="9.13. Text Search Functions and Operators">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="functions-xml.html" title="9.15. XML Functions">Next</a></td></tr></table><hr /></div><div class="sect1" id="FUNCTIONS-UUID"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.14. UUID Functions <a href="#FUNCTIONS-UUID" class="id_link">#</a></h2></div></div></div><a id="id-1.5.8.20.2" class="indexterm"></a><a id="id-1.5.8.20.3" class="indexterm"></a><a id="id-1.5.8.20.4" class="indexterm"></a><a id="id-1.5.8.20.5" class="indexterm"></a><a id="id-1.5.8.20.6" class="indexterm"></a><a id="id-1.5.8.20.7" class="indexterm"></a><p> <a class="xref" href="functions-uuid.html#FUNC_UUID_GEN_TABLE" title="Table 9.45. UUID Generation Functions">Table 9.45</a> shows the <span class="productname">PostgreSQL</span> functions that can be used to generate UUIDs. </p><div class="table" id="FUNC_UUID_GEN_TABLE"><p class="title"><strong>Table 9.45. <acronym class="acronym">UUID</acronym> Generation Functions</strong></p><div class="table-contents"><table class="table" summary="UUID Generation Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature"> Function </p> <p> Description </p> <p> Example(s) </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature"> <code class="function">gen_random_uuid</code> ( ) → <code class="returnvalue">uuid</code> </p> <p class="func_signature"> <code class="function">uuidv4</code> ( ) → <code class="returnvalue">uuid</code> </p> <p> Generates a version 4 (random) UUID </p> <p> <code class="literal">gen_random_uuid()</code> → <code class="returnvalue">5b30857f-0bfa-48b5-ac0b-5c64e28078d1</code> </p> <p> <code class="literal">uuidv4()</code> → <code class="returnvalue">b42410ee-132f-42ee-9e4f-09a6485c95b8</code> </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> <code class="function">uuidv7</code> ( [<span class="optional"> <em class="parameter"><code>shift</code></em> <code class="type">interval</code> </span>] ) → <code class="returnvalue">uuid</code> </p> <p> Generates a version 7 (time-ordered) UUID. The timestamp is computed using UNIX timestamp with millisecond precision + sub-millisecond timestamp + random. The optional parameter <em class="parameter"><code>shift</code></em> will shift the computed timestamp by the given <code class="type">interval</code>. </p> <p> <code class="literal">uuidv7()</code> → <code class="returnvalue">019535d9-3df7-79fb-b466-fa907fa17f9e</code> </p></td></tr></tbody></table></div></div><br class="table-break" /><div class="note"><h3 class="title">Note</h3><p> The <a class="xref" href="uuid-ossp.html" title="F.49. uuid-ossp — a UUID generator">uuid-ossp</a> module provides additional functions that implement other standard algorithms for generating UUIDs. </p></div><p> <a class="xref" href="functions-uuid.html#FUNC_UUID_EXTRACT_TABLE" title="Table 9.46. UUID Extraction Functions">Table 9.46</a> shows the <span class="productname">PostgreSQL</span> functions that can be used to extract information from UUIDs. </p><div class="table" id="FUNC_UUID_EXTRACT_TABLE"><p class="title"><strong>Table 9.46. <acronym class="acronym">UUID</acronym> Extraction Functions</strong></p><div class="table-contents"><table class="table" summary="UUID Extraction Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature"> Function </p> <p> Description </p> <p> Example(s) </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature"> <code class="function">uuid_extract_timestamp</code> ( <code class="type">uuid</code> ) → <code class="returnvalue">timestamp with time zone</code> </p> <p> Extracts a <code class="type">timestamp with time zone</code> 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. </p> <p> <code class="literal">uuid_extract_timestamp('019535d9-3df7-79fb-b466-fa907fa17f9e'::uuid)</code> → <code class="returnvalue">2025-02-23 21:46:24.503-05</code> </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> <code class="function">uuid_extract_version</code> ( <code class="type">uuid</code> ) → <code class="returnvalue">smallint</code> </p> <p> Extracts the version from a UUID of one of the variants described by <a class="ulink" href="https://datatracker.ietf.org/doc/html/rfc9562" target="_top">RFC 9562</a>. For other variants, this function returns null. For example, for a UUID generated by <code class="function">gen_random_uuid()</code>, this function will return 4. </p> <p> <code class="literal">uuid_extract_version('41db1265-8bc1-4ab3-992f-885799a4af1d'::uuid)</code> → <code class="returnvalue">4</code> </p> <p> <code class="literal">uuid_extract_version('019535d9-3df7-79fb-b466-fa907fa17f9e'::uuid)</code> → <code class="returnvalue">7</code> </p></td></tr></tbody></table></div></div><br class="table-break" /><p> <span class="productname">PostgreSQL</span> also provides the usual comparison operators shown in <a class="xref" href="functions-comparison.html#FUNCTIONS-COMPARISON-OP-TABLE" title="Table 9.1. Comparison Operators">Table 9.1</a> for UUIDs. </p><p> See <a class="xref" href="datatype-uuid.html" title="8.12. UUID Type">Section 8.12</a> for details on the data type <code class="type">uuid</code> in <span class="productname">PostgreSQL</span>. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-textsearch.html" title="9.13. Text Search Functions and Operators">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-xml.html" title="9.15. XML Functions">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.13. Text Search Functions and Operators </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.4 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 9.15. XML Functions</td></tr></table></div></body></html>