## Syntax ```mermaid %%{init: { 'theme': 'base', 'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' }, 'themeVariables': { 'fontSize': '11px', 'fontFamily': 'Arial' } }}%% flowchart LR Start((START)) --> UUIDV7[UUIDV7]:::quoted UUIDV7 --> End((END)) ``` ## Purpose The `UUIDV7` SQL function creates a new UUID of version 7 (RFC 9562). The first 48 bits of such a UUID hold the time of creation in milliseconds since 1970-01-01 00:00:00 UTC, so the UUIDs sort by creation time and the time can be read back with [[UUID_EXTRACT_TIMESTAMP]]. The other 74 bits are random. Two UUIDs created within the same millisecond differ, but they are not guaranteed to be in order of creation. Use `UUIDV7` where the time of creation is of use, such as an ID of a message or of an event. Use [[NEWID]] where an ID must not betray when it was made. The function is available under the same name in PostgreSQL 18. Available from release 28.0. See also [[UUID_EXTRACT_TIMESTAMP]], [[UUID_EXTRACT_VERSION]], [[UUIDV4]], [[UUID_GENERATE_V6]] and [[NEWID]]. Parameters: - Shift (optional, `number`): the shift of the time in days. Write an `interval` to shift by hours or minutes, such as `interval '-1 hour'`. A shift which is `null` gives `null`. A shift which moves the time outside the years 1970 to 10889 raises `itgenttn524`. Returns: the new UUID, of data type `guid`. Each call creates a UUID of its own, also within one row or one statement. ## Examples The following example creates a new UUID of version 7. The actual value differs per invocation: ```sql select uuidv7() ------------------------------------ 019b0f2e-6c1a-7a52-9d3e-4f1c8b27a0d5 ``` The following example creates a UUID of version 7 and reads its version: ```sql select uuid_extract_version(uuidv7()) version ------- 7 ``` The following example creates a UUID of version 7 with a time one hour in the past, for instance to test a query on the time of a UUID: ```sql select uuid_extract_timestamp(uuidv7(interval '-1 hour')) one_hour_ago ```