BUG #19738: `uuidv7(interval)` rejects sub-millisecond timestamps within the final 48-bit millisecond - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #19738: `uuidv7(interval)` rejects sub-millisecond timestamps within the final 48-bit millisecond
Date
Msg-id 19738-659d03aaa312f3b8@postgresql.org
Whole thread
Responses Re: BUG #19738: `uuidv7(interval)` rejects sub-millisecond timestamps within the final 48-bit millisecond
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      19738
Logged by:          Shallow
Email address:      theshallow27@gmail.com
PostgreSQL version: 18.6
Operating system:   Linux
Description:

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.





pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #19737: Empty `JSON_OBJECT` cannot use documented `ON NULL` or unique-key clauses
Next
From: PG Bug reporting form
Date:
Subject: BUG #19739: Parameterized first autocommit statement can have different `transaction_timestamp()` and `statement