Re: BUG #19738: `uuidv7(interval)` rejects sub-millisecond timestamps within the final 48-bit millisecond

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: theshallow27(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19738: `uuidv7(interval)` rejects sub-millisecond timestamps within the final 48-bit millisecond
Date: 2026-10-04 13:54:39
Message-ID: 33f0828a80f76e6adcefda8fd788113e69df755e.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 2026-10-02 at 22:36 +0000, PG Bug reporting form wrote:
> PostgreSQL version: 18.6
>
> UUIDv7 stores a 48-bit Unix-millisecond timestamp, and PostgreSQL's
> documentation says its timestamp also includes sub-millisecond precision. A
> shifted timestamp 250 microseconds into the final representable millisecond
> is
> rejected as out of range, although its millisecond field is still the
> maximum
> valid value.
>
> **Reproduction:**
>
> ```sql
> SELECT uuidv7(
>     (timestamptz '1970-01-01 UTC'
>      + interval '281474976710655 milliseconds'
>      + interval '250 microseconds')
>     - clock_timestamp()
> );
> ```
>
> **Actual result:** SQLSTATE `22008`, `timestamp out of range for UUID
> version 7`.
>
> **Expected result:** Generate a UUIDv7 whose 48-bit millisecond timestamp is
> `2^48 - 1`, preserving the permitted sub-millisecond component.

I think that is a non-bug.

uuidv7(interval) gets the actual current timestamp (just like clock_timestamp
does) and adds that to the interval argument. That call is a bit later than
the clock_timestamp in your statement, so the result is maybe bigger than the
timestamp you specified, so it might exceed the maximum possible timestamp.

And anyway, discussing the oddities of uuidv7() for a timestamp in the year
10889 is somewhat irrelevant...

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-10-04 16:03:24 Re: BUG #19738: `uuidv7(interval)` rejects sub-millisecond timestamps within the final 48-bit millisecond
Previous Message Laurenz Albe 2026-10-04 13:39:32 Re: BUG #19740: `has_language_privilege` returns TRUE for a nonexistent language OID when the user is a superuser