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 1wcRhL-003LvV-0I for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jun 2026 17:47:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcRhJ-001ssu-2w for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jun 2026 17:47:37 +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 1wcRhJ-001ssm-20 for pgsql-hackers@lists.postgresql.org; Wed, 24 Jun 2026 17:47:37 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wcRhG-0000000049I-3hVF for pgsql-hackers@lists.postgresql.org; Wed, 24 Jun 2026 17:47:36 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-36d98b9aa9aso1129478a91.3 for ; Wed, 24 Jun 2026 10:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782323251; cv=none; d=google.com; s=arc-20240605; b=HUPYMRrLHq+4Vdvbrg7s7yMHch5/mLisVzgqoCZIYGuHbTfr97avA19wvC5EjKSXGN YhMu6UDcWE6OwlnnZUOzYP16wSrszVjcMwG4KJNx/aJ9DBIea0zSLcS177FhbgSJl7PA gpD/6iDBGzZO+i08QKVcXkaRrtVL3U2+RQRCwbYoAqHJ6F+mFmgp1R5lz/EiITMyMoI+ OPWyJw1KCZrGiooWh+gDNK4EdjGKKRItZh+xxxB7MuDIPVaDaqZLVh9NEZm6PmhjHBJ8 RE1e3eLw72ar6AY7ot+IvN3UIpJTegt2zZ78hdDDPzohxN7rvhlnqT9mMTmq0/SYhRe7 R7KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=UOtxxf5piLNkiUCr8/akXThoAgHoNdq4AXo029wEYRA=; fh=Z0vot1IbCkK4/5lHAMjoclynRFfts+Y6Y/0peiPwTgU=; b=XuhHRfXnUU/Y4nP7b3idN+Zzn8V87wV2GL2EVyWQxVEnnS93HiDA+I/VfAlvWqrS+X zlCap6omZLnyCipoDP6lHxEbYHaYLrTEhsE9dgvDiX2rGV24mHS0j4W0Enhkh5ixY++M P1qW+l0wfZYRoKxPXrDXSWdz5ZDa4Y9xpI0tSqg8BsNsXLC/2eLNlMnFHl0+HznbKyA5 BWXs7tkc/mb6aStGiai1PWP89VkvSbN5HQaRdsJVYrpjVAc/QvHx+DzuKP3orjbTfc9e nRPkEo4pePijGitLXWri5WDwKXIpmWVggt3XUb78huw+7d3tyVWMT2zfBqJe+FmuJo3C ebew==; 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=1782323251; x=1782928051; 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=UOtxxf5piLNkiUCr8/akXThoAgHoNdq4AXo029wEYRA=; b=iW0c2Ul/3sW/dvaJBcJvgWD7CTNn6s1wEECk3R6xwEU1luumnghJx99UPNG7xm0Lxz oIQrDNR1S/kEyYiPalcr29dqfsG/NmihPQ8tL/3OSsiWKPGj9Fpxt1FEk4f1lPP5kp6Y x0LXflaIfY//Sp3hhmXvotcEH44r5cXsUshkwm/RYmJW6BFn59T+bHZuwBtXncwxmEEl IWMTonGyNpjXtXXyjEAnnCSjnCFLqGFEUzJiiODLCDgCjVDDJrQEXeIBo2wRXSG/tjPx ivssv837YyOhTJmQrhblrRyICE4pkziyzHfcMGK3A0OwS316W6O3jLHV7PZJYUgERywz WeAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782323251; x=1782928051; 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=UOtxxf5piLNkiUCr8/akXThoAgHoNdq4AXo029wEYRA=; b=YFsxB1oZGHYjN5tX9i9NdJr1TCve0pXuO/It5fklbID3YrEV1LeGbBqo+B88KKnuf0 Txb7FszjesrD40U09CHiOAAwVS7kgeQ51//Gtpv9beEb6Dxn6s/dWCrym3mryqp48v9l TJ0KA1gnswkwclgthjTu9msqz44QWnJEYDJFCIyPUWOL0q8ddBsU8QpT9FQGSsHlWqkS U0Fdv9NRJnaREqfBa0LVXAQGy2GWLOmnC+rrrCkI+niCzlGyd//VDeJ4bI+KAbq6GVRz eY53XeWLmipvx/6uAfGOCPbXixwDK63MxhIwNJrKV/BbppDzVeh+yJ9vs0fX6jWJqdxJ ZCqw== X-Forwarded-Encrypted: i=1; AHgh+RqAHwLZo6DNb+CQZ4lkK4aQaBEGu2hDoCKq0G37CGRGh6rcmLONwOidf+6b8GqPmXcM5fCLorBQXetM1pth@lists.postgresql.org X-Gm-Message-State: AOJu0YyiOuuldZl8NXbOnPw8J6NKk3mzS8tYLbNkDAp7eup4UWhMpC67 sdkJmfy/Psc6HpgMKikEVyUs8RfnklsylC9AnzrnyZagdkGkN3uzw5wJ4LCi8MYKdlL/5lCuuFg PP73KLcJjq/OBUuJgLuF2zLlttyUrskk= X-Gm-Gg: AfdE7cl6M35RDTl3cOBumPdP9gpkM+jHs7wU7EvA7uAHo2w/c4vMRB5HIymc7w3+SRt NIQIc1MNsQMoRmrnoRKndpKV3iLlEoe+HzwtOa45KyB8JCB5aLZPB9XutYYGlcWax8vN2atXrlY h7XiU2droQ8wbBBIgzeWLAEZpCvhtCAsBbVQCvaZyfX+wPxkv/hzPCMs5vR0I+mRZ4vlpaVTXVk eO/3CHAI8LrjSneS2INFmxHy2GC//5qZegXGsRhx4Dsy1eDgBKxgCqbnJRIxlBDO1hCcc8A2on8 +wKT+yNSmKn7cWgwtMTNg5bQslxClQ== X-Received: by 2002:a17:90b:584b:b0:37c:18e0:90ed with SMTP id 98e67ed59e1d1-37dd0d0d820mr8919095a91.4.1782323251216; Wed, 24 Jun 2026 10:47:31 -0700 (PDT) MIME-Version: 1.0 References: <799A70FA-6E5C-4118-99EB-2FBBE1CBAC54@thebuild.com> <966B5430-8ECD-48FA-B56F-22452D9CDBBF@yandex-team.ru> In-Reply-To: From: Masahiko Sawada Date: Wed, 24 Jun 2026 10:46:54 -0700 X-Gm-Features: AVVi8CdeCirz3r_U6-SZu4y-QZ_32OVpAXQw_99ygv0wMmfT6DVkm5h6sDRWhYM Message-ID: Subject: Re: uuidv7 improperly accepts dates before 1970-01-01 To: Baji Shaik Cc: Christophe Pettus , Andrey Borodin , 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 Fri, Jun 12, 2026 at 3:35=E2=80=AFPM Baji Shaik w= rote: > > On Thu, Jun 11, 2026 at 2:20=E2=80=AFPM Masahiko Sawada wrote: >> >> I think we should go ahead and add both upper and lower bound checks, >> barring objections. > > > Thanks Masahiko. Here's a patch series that adds both boundary > checks along with the infinity check from my earlier patch: > > 0001 - Reject timestamps before the Unix epoch (lower bound) > 0002 - Reject infinite intervals > 0003 - Reject timestamps beyond the 48-bit field limit (upper bound) > > Christophe's original v1 covered the pre-epoch case; 0001 is > essentially the same fix with slightly different wording. I have > included it here so the series is self-contained and applies > cleanly on HEAD. Happy to drop it in favor of Christophe's > version if you prefer that. > > The infinity check (0002) goes before the epoch conversion so > that uuidv7('infinity'::interval) gets a clear "infinite timestamps" > message rather than falling through to the pre-epoch check > with a confusing detail. > > All three use ERRCODE_DATETIME_VALUE_OUT_OF_RANGE with errdetail. Thank you for creating the patches! Here are some review comments: + /* + * Reject infinite intervals. timestamptz_pl_interval() can produce an + * infinite timestamp when the input interval is infinite, and converti= ng + * that to a Unix epoch value would overflow. + */ + if (TIMESTAMP_NOT_FINITE(ts)) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range for UUID version 7"), + errdetail("UUID version 7 does not support infinite timestamps."))); + I think we can do this check earlier, like before shifting the timestamp, and we can mention in the doc that we don't accept 'infinity' and '-infinity' values. --- + /* + * The UUID version 7 timestamp field is 48 bits wide, storing + * milliseconds since the Unix epoch. Reject timestamps that would + * overflow this field (dates beyond approximately year 10889). + */ + if (us / US_PER_MS > (int64) 0xFFFFFFFFFFFF) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range for UUID version 7"), + errdetail("UUID version 7 does not support timestamps beyond approximately year 10889."))); Please use INT64CONST() instead. --- I think we need to mention in the doc that timestamp shifting beyond the range UUIDv7 can support is not accepted. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com