Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1weLFd-004jgP-1r for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2026 23:18:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1weLFc-0059OO-0x for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2026 23:18:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1weLFb-0059OG-3A for pgsql-hackers@lists.postgresql.org; Mon, 29 Jun 2026 23:18:52 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1weLFZ-00000000sCP-1wS8 for pgsql-hackers@lists.postgresql.org; Mon, 29 Jun 2026 23:18:51 +0000 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-37d82f3a244so1666554a91.2 for ; Mon, 29 Jun 2026 16:18:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782775126; cv=none; d=google.com; s=arc-20260327; b=YLIHNyulT/gELXpmewdSH3XlUGcIGJHLZwI+nWer0VC7sKK/LN/ATA8N/IPGYLUap6 yQqZOakT3y6wMY+2/7yWFO9cZ9vC011l7MtkHcGp0fxMoMufky4Y9n6ZhASsfBxuZkYW bcaQdCRSXxSarskOkEnFkFLoM9WXTsv14l7IldGpy1M3PqMAurjjw3ameMKBgY3EZ6EF AUqbB1e3nPQtMz6U6+PYZB8fG8TL9yaYlCc0lLF53GKD/tqOLN37trC0JxZLXzBT4r1m rHW3d6/+NvjC7mk3bhgBJpb13BjvUWd5QenXicuuCyGwMXBcq0pSkg9MOUr8qPMIy8AX ujzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=suMA4qXdoFcTsmS/bt0q25aVMF9LAa1ITkzJ/QhUTys=; fh=/rh4g++KdInAutMeMKu7t5rLsLNAXWXFnIgq+Py7YAY=; b=VLsVZI2g0T5GuRIbZumTlclpbOwNyoyIHHHaRFPcAwK1EhH1GBNod+VXOsk0oHx/Aw zef1yEPYSfP9soFoFPfMvlfxdloH7GB0XEQA6NLhlCgywmxAckOWxfuqaWgEnq9JH6PR HGfhWqfO4TX91Fb2ddXhgGkh2zCET3th49aVwhqwRxZPI6KIeY08xZJdij/Ox5BO5o57 81/N41B8s0VH7Ikna1RGR/2xu5jzqBZKB7SrCJo5DaUxpGHSEwl4dTrKnkFFf2F+m+q/ xzFNwRYl9d1VnbQ003qS4rN3wzv5qtizCQr6z0cbaqChdhzibfNPOmm1cMCoMPiREVzs DLdA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782775125; x=1783379925; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=suMA4qXdoFcTsmS/bt0q25aVMF9LAa1ITkzJ/QhUTys=; b=lOq7vgvrfDZPw9BGJ7+KJd5ivY5WtQr7QvCM8QZTA38u8cbAiEJ7o/3ZyMYH00P3Ts UFnIaxJV5fLsOMd42asc1XhRsoVFyLTuku1U+/2hbR1kay/gkNcH2VBAjECgpV0UgNYh JDqRfYOB9QvMPo6L60LfyXksFw/uqj7sQ3//4PFBzI/Nk4fPQfcAFLh2WeXZj0wQzWxJ q4NtSXwlONsLZ0b79FTlVw15W6ibvN82EndwzPOs7ioTadlvIkJ/pcysWoabKuZfFZ0p pL0fWHcgafpRcGoeCWoGEIwFPn96Ky4zKDPjNttJbQLKKGh5KBhDvU/+hRsyXc/Wgq9W c8mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782775125; x=1783379925; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=suMA4qXdoFcTsmS/bt0q25aVMF9LAa1ITkzJ/QhUTys=; b=ek0/vaTnisMtjXX2xZSlXfNZjPsVp5UCFjpkta1X5AMcx23Wf/ek/H3F/hOilx4Iad 2hhS3emG0XWk26pu9zAe2KyHoHltaTUiy+A4LYZy6KH1RnBjM/CBR6Fsr0f5XRQr5FsU Q77G+JwThsKpCkEsToxuobyhnbumlFTHK75F8N8GtOBve5vmuEYQDT2RJ6qY4aX+y1yI QmzMDdG/z5W8qA4nBa6hYbgunu6PDTco/h7NblP6s5040chEqb930e5kBMQ5eKMGuEx0 9zc0IDjlRUBPWIE6J/K5lMs+DebFZKbn0tJHmjfTpts1IIvFJjOxTg/nG2X3syXmms8s OsGw== X-Forwarded-Encrypted: i=1; AHgh+RqClDQS8YX2dJ5eU6kWXK4uTkhoKkg1E9IbpsfWKm1SQ4lOgnQsK8Xg9EjSLPJpFxIstWx9eMmbM7Pr8I3K@lists.postgresql.org X-Gm-Message-State: AOJu0YyH7jgmZjSFnNRe6sCaZmQzNFBdlLYCIGlaFmfH0MRHPXNV8WQA Ijf/gUd6w/0LQrAzXtUFLBIL3kXYieGXyeflH0rlb+j55SNqncQZgIGCkRaUeTfcbuxt1TCwIOR H41LRxAhf4eKL/g8gWcTD3hyvCp+c1VI= X-Gm-Gg: AfdE7cl3taILn6jUgA/svGYifEneXy5gvJkNdK4tlboqv2pIyKbsHDV3LXBh6DLu8ft yl8EChiykbnsYKsdcyRYAf1yxx9cITZ/zsfIrQdqPfNL/amj3xrHyKE+04zFuJDbVIOt6VAVVyz z4vyCU5YnEY1qSGZj67u+/U0Qjy/802zOTVEJcqh15szJcMnxBkzypxtU833rZWZEtf7J+QT4iy /WTY93y+b0olRoBceG4/uIn7D/nl030e0lr6+TxGySTg3ZQpgUQGqwwyv4u9aGSmr/8UlGD5Q== X-Received: by 2002:a17:902:d588:b0:2ca:320:f74b with SMTP id d9443c01a7336-2ca2e4309a7mr9678735ad.21.1782775125506; Mon, 29 Jun 2026 16:18:45 -0700 (PDT) MIME-Version: 1.0 References: <20260625.111954.696627555349573162.horikyota.ntt@gmail.com> In-Reply-To: From: Masahiko Sawada Date: Mon, 29 Jun 2026 16:18:08 -0700 X-Gm-Features: AVVi8Ccfs8GFyQR4Ge4sAgfHKNx1O51tNoRX6SpKBohSnlYX1u75ei7dwFQ_2UM Message-ID: Subject: Re: uuidv7 improperly accepts dates before 1970-01-01 To: Baji Shaik Cc: Kyotaro Horiguchi , zsolt.parragi@percona.com, pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jun 25, 2026 at 6:47=E2=80=AFAM Baji Shaik w= rote: > > On Wed, Jun 24, 2026 at 9:19=E2=80=AFPM Kyotaro Horiguchi wrote: >> >> From a user's perspective, it seems sufficient to know that the >> shifted timestamp falls outside the range supported by UUID v7. As a >> translator, I'm not particularly enthusiastic about adding more >> message variants when the distinction is not particularly useful to >> users. > > > Thanks for the feedback, Kyotaro. Good point. Attached v3 with all bounda= ry checks > using a single shared errdetail: > > "UUID version 7 supports timestamps from 1970-01-01 to approximately yea= r 10889." > > 0001 - Reject infinite intervals > 0002 - Reject pre-epoch timestamps (with overflow-safe epoch conversion) > 0003 - Reject timestamps beyond the 48-bit limit > > I prefer keeping them as 3 patches since each addresses a distinct > failure mode and is easier to review/bisect independently. That said, > since 0002 and 0003 now share the same errdetail and are logically > the same validation (timestamp outside valid range), I'm happy to > merge them into one patch for v4 if preferred. > Thank you for updating the patch! I have one comment: + /* + * Convert a TimestampTz value back to a UNIX epoch timestamp. Use + * overflow-safe addition since large intervals can exceed int64 range. + */ + if (pg_add_s64_overflow(ts, + (int64) (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDAT= E) * + SECS_PER_DAY * USECS_PER_SEC, + &us)) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range for UUID version 7"), + errdetail("UUID version 7 supports timestamps from 1970-01-01 to approximately year 10889."))); 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. --- + /* UUID v7 uses an unsigned 48-bit millisecond field; reject pre-epoch = */ + if (us < 0) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range for UUID version 7"), + errdetail("UUID version 7 supports timestamps from 1970-01-01 to approximately year 10889."))); + + /* Reject timestamps beyond the 48-bit millisecond field maximum */ + if (us / US_PER_MS > (INT64CONST(1) << 48) - 1) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range for UUID version 7"), + errdetail("UUID version 7 supports timestamps from 1970-01-01 to approximately year 10889."))); Let's merge these two if statements as they use the same error message. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com