Re: uuidv7 improperly accepts dates before 1970-01-01

From: Baji Shaik <baji(dot)pgdev(at)gmail(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, zsolt(dot)parragi(at)percona(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: uuidv7 improperly accepts dates before 1970-01-01
Date: 2026-07-03 16:34:51
Message-ID: CA+fm-RM5sNuGrufK7cMstQu=3BJrXxLzsMYp6GGiKBOBn2cE4g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Mon, Jun 29, 2026 at 6:18 PM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
wrote:

> It does the range validation on the Unix-epoch value, after converting
> back from the shifted PostgreSQL-epoch timestamp. Can we compare
> pre-compute the Unix-epoch timestamp resentable window in
> PostgreSQL-epoch units against the shifted PostgreSQL-epoch timestamp
> before converting it back to the Unix epoch? That way, we don't need
> to worry about the overflow.
>
> Let's merge these two if statements as they use the same error message.
>

Thanks for the review. Attached v4 addressing your feedback:

- 0002 now pre-computes the valid timestamp range in PostgreSQL-epoch
units (UUIDV7_MIN_TIMESTAMP / UUIDV7_MAX_TIMESTAMP) and validates
the shifted TimestampTz directly, before converting to Unix epoch.
This eliminates the overflow concern entirely.

- The pre-epoch and upper-bound checks are merged into a single if
statement.

0001 (infinite intervals) is unchanged from v3.

Thanks,
Baji Shaik

Attachment Content-Type Size
v4-0002-Reject-out-of-range-timestamps-in-uuidv7-interval.patch application/octet-stream 6.0 KB
v4-0001-Reject-infinite-intervals-in-uuidv7-interval.patch application/octet-stream 3.2 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Ayush Tiwari 2026-07-03 16:48:13 Re: Fw:Re: Fw: gbt_var_consistent in contrib/btree_gist/btree_utils_var.c has internal-node type confusion on the <> strategy, bypassing exclusion constraints
Previous Message Tom Lane 2026-07-03 13:50:30 Re: Fw:Re: Fw: gbt_var_consistent in contrib/btree_gist/btree_utils_var.c has internal-node type confusion on the <> strategy, bypassing exclusion constraints

Browse pgsql-hackers by date

  From Date Subject
Next Message Nisha Moond 2026-07-03 16:45:03 Re: Support EXCEPT for TABLES IN SCHEMA publications
Previous Message Florin Irion 2026-07-03 16:26:03 Re: [PATCH] pg_get_domain_ddl: DDL reconstruction function for CREATE DOMAIN statement