Protect against timestamp underflow in uuidv7(interval)
Protect against timestamp underflow in uuidv7(interval)
We were silently allowing underflowing the generated timestamp for the
UUIDv7 value:
# SELECT uuid_extract_timestamp(uuidv7('-57 years'::interval));
uuid_extract_timestamp
-----------------------------
10889-01-23 04:02:36.375+00
(1 row)
RFC 9562[0] doesn't seem to specify that this should be allowed, so
generate an error and forbid the underflow.
I checked the Rust uuid crate[1], and it also errors out with
a timestamp earlier than the Unix epoch.
[0]: https://www.rfc-editor.org/rfc/rfc9562.html
[1]: https://github.com/uuid-rs/uuid/blob/1e6a9669e30d53bae50fd52f16b7a1961fda236b/src/timestamp.rs#L198-L220
--
Tristan Partin
PostgreSQL Contributors Team
AWS (https://aws.amazon.com)
Re: Protect against timestamp underflow in uuidv7(interval)
От:
Baji Shaik <baji.pgdev@gmail.com>
Дата:
On Tue, Jun 23, 2026 at 6:39 PM Tristan Partin <tristan@partin.io> wrote:
We were silently allowing underflowing the generated timestamp for the
UUIDv7 value:
# SELECT uuid_extract_timestamp(uuidv7('-57 years'::interval));
uuid_extract_timestamp
-----------------------------
10889-01-23 04:02:36.375+00
(1 row)
Thank you, Tristan.
This has been reported and is being discussed here [1]
[1]: https://www.postgresql.org/message-id/CA%2Bfm-RN4eMEr2tzZU_mAV-%3DWfdmPXJ4Ea_GpmSS8%3DyStSy8onQ%40mail.gmail.com
[1]: https://www.postgresql.org/message-id/CA%2Bfm-RN4eMEr2tzZU_mAV-%3DWfdmPXJ4Ea_GpmSS8%3DyStSy8onQ%40mail.gmail.com
Thanks,
Baji Shaik.
Baji Shaik.