Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion content/references/datatypes/uuid.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ insert into example2 select uuidv7();
-- To shift the current timestamp
insert into example2 select uuidv7('-1 hour');
select id from example2;
---
```

```
Expand All @@ -74,3 +73,38 @@ select uuid 'a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11';
select uuid '{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}';
```

## UUID Extraction Functions

### uuid_extract_version
Provided with a valid UUID, `uuid_extract_version` extracts the version in a `smallint`. Otherwise the function returns `NULL`.

```sql
select uuid_extract_version(gen_random_uuid());
----
4

select uuid_extract_version(uuidv7());
----
7

select uuid_extract_version('11111111-1111-5111-8111-111111111111'::uuid) --invalid uuid
----
NULL
```

### uuid_extract_timestamp
`uuid_extract_timestamp` extracts the timestamp with time zone of a uuid of version 1 or 7. Otherwise, the function returns `NULL`.

```sql
SET timezone = 'Europe/Berlin'; --The timestamp displayed depends on the timezone

SELECT uuid_extract_timestamp('C232AB00-9414-11EC-B3C8-9F6BDECED846'::uuid); --version 1
----
Tuesday, February 22, 2022 2:22:22.00 PM GMT+05:00

SELECT uuid_extract_timestamp('017F22E2-79B0-7CC3-98C4-DC0C0C07398F'::uuid); --version 7
----
Tuesday, February 22, 2022 2:22:22.00 PM GMT+05:00
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+05 doesn't look like Europe/Berlin

```