# UUID

Key: `representation.identifier.uuid`

Universally Unique Identifier (RFC 9562, which obsoletes RFC 4122). Versions include v1 (timestamp-based), v4 (random), v5 (name-based), and v6, v7 and v8 (time-ordered and custom layouts). Text form: 8-4-4-4-12 hex groups with hyphens; the hex digits may be upper, lower or mixed case, and lowercase is preferred.

Page: <https://meridian.online/docs/projects/finetype/types/representation/identifier/uuid>

Samples: `550e8400-e29b-41d4-a716-446655440000`, `6ba7b810-9dad-11d1-80b4-00c04fd430c8`, `f47ac10b-58cc-4372-a567-0e02b2c3d479`

## Background

### Origin

UUIDs were originally used in the Apollo Network Computing System (NCS), later in the Open Software Foundation's Distributed Computing Environment (DCE), and then in Microsoft Windows platforms.[[1]](https://www.rfc-editor.org/rfc/rfc9562) Apollo Computer's Network Computing System, which used UUIDs, was launched in 1987.[[2]](https://en.wikipedia.org/wiki/Universally_unique_identifier) Microsoft Windows platforms adopted the NCS, and later the DCE, design as Globally Unique Identifiers (GUIDs) in the early nineties.[[2]](https://en.wikipedia.org/wiki/Universally_unique_identifier) ISO/IEC documented the DCE design in 1996, in ISO/IEC 11578:1996.[[2]](https://en.wikipedia.org/wiki/Universally_unique_identifier)

RFC 4122, A Universally Unique IDentifier (UUID) URN Namespace, was published in July 2005.[[3]](https://www.rfc-editor.org/rfc/rfc4122.txt) RFC 9562 says an ITU-T Recommendation and an ISO/IEC Standard are derived from RFC 4122.[[1]](https://www.rfc-editor.org/rfc/rfc9562) RFC 9562 says the ITU-T and ISO/IEC specifications and the RFC have been aligned and are fully technically compatible.[[1]](https://www.rfc-editor.org/rfc/rfc9562)

RFC 9562 gives as one of the main reasons for using UUIDs that no centralised authority is required to administer them.[[1]](https://www.rfc-editor.org/rfc/rfc9562) RFC 9562 says UUIDs have gained popularity as database keys because the auto-increment schemes often used by databases do not work well in distributed applications.[[1]](https://www.rfc-editor.org/rfc/rfc9562) RFC 9562 says UUID versions that are not time ordered, such as UUIDv4, have poor database-index locality.[[1]](https://www.rfc-editor.org/rfc/rfc9562) UUIDv7 places a Unix timestamp in milliseconds in the most significant 48 bits of the UUID.[[1]](https://www.rfc-editor.org/rfc/rfc9562) RFC 9562 says implementations should use UUIDv7 instead of UUIDv1 and UUIDv6 if possible.[[1]](https://www.rfc-editor.org/rfc/rfc9562)

### Use

RFC 9562 says UUIDs comprise the core identifier infrastructure for many operating systems such as Microsoft Windows and applications such as the Mozilla web browser.[[1]](https://www.rfc-editor.org/rfc/rfc9562) A UUID is 128 bits long.[[1]](https://www.rfc-editor.org/rfc/rfc9562) RFC 9562 calls the standard text form of a UUID the hex-and-dash string format, groups of hexadecimal characters separated by single hyphens.[[1]](https://www.rfc-editor.org/rfc/rfc9562) PostgreSQL writes a UUID as a group of 8 hexadecimal digits, then three groups of 4 digits, then a group of 12 digits, for 32 digits in total.[[4]](https://www.postgresql.org/docs/current/datatype-uuid.html)

Microsoft's .NET Guid.ToString method can write a GUID as 32 digits with no hyphens, with hyphens, with hyphens enclosed in braces, or with hyphens enclosed in parentheses.[[5]](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=net-10.0) By default, .NET's Guid.ToString writes lowercase hexadecimal digits in groups of 8, 4, 4, 4 and 12, separated by hyphens.[[5]](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=net-10.0) Python's uuid module accepts a string of hex digits with or without curly braces, hyphens and a URN prefix.[[6]](https://docs.python.org/3/library/uuid.html) PostgreSQL accepts UUID input surrounded by braces, or with some or all hyphens omitted.[[4]](https://www.postgresql.org/docs/current/datatype-uuid.html) PostgreSQL always outputs a UUID in the standard form.[[4]](https://www.postgresql.org/docs/current/datatype-uuid.html) When a column mixes these spellings, normalise every value to the bare hyphenated form before you compare or join on it. (Meridian's view) A 32-character hexadecimal string with no hyphens may be a UUID with its hyphens stripped, or something else entirely, so find out where it came from before you cast it. (Meridian's view)

In the text form of a UUID, the version is the hex digit after the second hyphen.[[2]](https://en.wikipedia.org/wiki/Universally_unique_identifier) DuckDB retrieves the version of a UUID value with the uuid\_extract\_version function.[[7]](https://duckdb.org/docs/current/sql/data_types/numeric) DuckDB retrieves the timestamp from a UUIDv7 value with the uuid\_extract\_timestamp function.[[7]](https://duckdb.org/docs/current/sql/data_types/numeric) RFC 9562 advises treating UUIDs as opaquely as possible and avoiding parsing them unless absolutely necessary.[[1]](https://www.rfc-editor.org/rfc/rfc9562) Look at the digit after the second hyphen to learn which version a column holds, but resist building logic that depends on what is inside the identifier. (Meridian's view)

RFC 9562 says UUIDs should be stored within database applications as the underlying 128-bit binary value where feasible.[[1]](https://www.rfc-editor.org/rfc/rfc9562) RFC 9562 notes that storing UUIDs as text requires 288 bits to represent a 128-bit value.[[1]](https://www.rfc-editor.org/rfc/rfc9562) DuckDB's UUID type uses 128 bits and is represented internally as HUGEINT values.[[7]](https://duckdb.org/docs/current/sql/data_types/numeric) DuckDB prints a UUID with lowercase hexadecimal characters separated by dashes, using 36 characters in total.[[7]](https://duckdb.org/docs/current/sql/data_types/numeric) SQL Server's uniqueidentifier data type is a 16-byte GUID.[[8]](https://learn.microsoft.com/en-us/sql/t-sql/data-types/uniqueidentifier-transact-sql?view=sql-server-ver17) SQL Server does not order uniqueidentifier values by comparing the bit patterns of the two values.[[8]](https://learn.microsoft.com/en-us/sql/t-sql/data-types/uniqueidentifier-transact-sql?view=sql-server-ver17) RFC 9562 notes that Microsoft's Component Object Model (COM) GUIDs use little-endian byte order when saved in binary, while RFC 9562 sequences all fields in big-endian format.[[1]](https://www.rfc-editor.org/rfc/rfc9562) Do not expect a set of UUIDs to sort the same way in every database, and when a binary GUID from a Microsoft system turns into a different string than its source shows, suspect byte order before you suspect the data. (Meridian's view)

RFC 9562 says implementations should not assume that UUIDs are hard to guess.[[1]](https://www.rfc-editor.org/rfc/rfc9562) Python's documentation notes that uuid1() may compromise privacy because it creates a UUID containing the computer's network address.[[6]](https://docs.python.org/3/library/uuid.html) RFC 9562 cautions database schema designers against using name-based UUIDs as primary keys in tables.[[1]](https://www.rfc-editor.org/rfc/rfc9562) PostgreSQL provides native support for generating UUIDs using the UUIDv4 and UUIDv7 algorithms.[[4]](https://www.postgresql.org/docs/current/datatype-uuid.html) DuckDB supports generating UUIDv4 and UUIDv7 identifiers.[[7]](https://duckdb.org/docs/current/sql/data_types/numeric) Python's uuid module added UUID versions 6, 7 and 8 in version 3.14.[[6]](https://docs.python.org/3/library/uuid.html)

### Where you'll meet it

GOV.UK's Publishing API uses a UUID value, content\_id, to identify distinct pieces of content on GOV.UK.[[9]](https://docs.publishing.service.gov.uk/repos/publishing-api/model.html) On GOV.UK, the same content\_id is used for content that is available in multiple translations.[[9]](https://docs.publishing.service.gov.uk/repos/publishing-api/model.html)

## Sources

1. [RFC 9562: Universally Unique IDentifiers (UUIDs) \| RFC Editor](https://www.rfc-editor.org/rfc/rfc9562) — standard
2. [Universally unique identifier - Wikipedia](https://en.wikipedia.org/wiki/Universally_unique_identifier) — secondary source
3. [A Universally Unique IDentifier (UUID) URN Namespace](https://www.rfc-editor.org/rfc/rfc4122.txt) — standard
4. [PostgreSQL: Documentation: 18: 8.12. UUID Type](https://www.postgresql.org/docs/current/datatype-uuid.html) — documentation
5. [Guid.ToString Method (System) \| Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=net-10.0) — documentation
6. [uuid — UUID objects according to RFC 9562 — Python 3.15.0 documentation](https://docs.python.org/3/library/uuid.html) — documentation
7. [Numeric Types – DuckDB](https://duckdb.org/docs/current/sql/data_types/numeric) — documentation
8. [uniqueidentifier (Transact-SQL) - SQL Server \| Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/data-types/uniqueidentifier-transact-sql?view=sql-server-ver17) — documentation
9. [publishing-api: Publishing API's Model - GOV.UK Developer Documentation](https://docs.publishing.service.gov.uk/repos/publishing-api/model.html) — organisation
