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 1wXkxX-003SWw-20 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jun 2026 19:20:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wXkxW-00GmGi-1j for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jun 2026 19:20:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wXkxW-00GmGa-0r for pgsql-hackers@lists.postgresql.org; Thu, 11 Jun 2026 19:20:58 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wXkxU-00000002E6t-1V11 for pgsql-hackers@lists.postgresql.org; Thu, 11 Jun 2026 19:20:57 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-c8589498839so64970a12.2 for ; Thu, 11 Jun 2026 12:20:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781205655; cv=none; d=google.com; s=arc-20240605; b=PD0GpT1jrwDWEiQEdNWA/on3ecg/fn2ODyODV7MZAODwlooKnp8J+RPr35L9q6OZ+W 10q09c4eUfcdpZd/H8O9Gr2g4U3lOdEyD1/BEP2YEaWmEwLbkqpbWig45lrWFmPpetak wSlWV9OOnkPJTS0CIrWgM6s9LZOh0z6Y3B89d9FuIoR3WrRlCIj3yBicBAKhdjluIAVT nlL8qlmwVSL4gXvNHKZWztO/Qlpz5SRNaBL5SQdu7CIcP8zrKQsAjFCJuiqXHSQZ92Dq mYaJGB396GC60UURhYSlLQuLAl/GrfOu9HXr2AfSmsTpjpJfuLkladxVvcBCwT3QuZqb h2CQ== 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=S1MsXvm+zBkz9lw3HlzxpjF1MBFOX2jvGbB1/7ITdk4=; fh=VwFouQNMeW7vPm7h/e1wXGYWMRUPXvE7FIeTBI3wMLw=; b=J/+hWLoakO2sTjFDFLN3MOs0ye8eoteKDRXqaDbvMe6rzZuVgRO7a5LGEvE5r80kAK ta51NV/F35aTbSXCluwhQtzlGMocM6SNXKOv12sSpcH0qvpebKHuazDxuT2IJ8np8nyY daWxGZHGRzPazuTCDsiWc3BNebHU/h3Kdpibk0sqGNxSrR3B8ohFm64uSwRlxXx8pJdQ VCoDV5ZF9kMLo9S6bbg4aBdhh7Jemb6FAHwUf/czrI5/7m2r4Kd0CVQ/yjK7BGd9g9Wh ohQWR5af7wqexV4yoVUeLcan9K8sXO6C9BdtwL3SrIknQxRNEbI6heqRFveHnUulivJa uH+w==; 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=1781205655; x=1781810455; 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=S1MsXvm+zBkz9lw3HlzxpjF1MBFOX2jvGbB1/7ITdk4=; b=hL7G28StQm5uXIKSN7UfsJsbj46cxdy+F6Afo3kdqKlFFBrVlUAmDWrFdD242BI9Pc k2ccJ6g5TIahWu8Ro/PVQmLLbzhDrm/aaGZ/YwvW897NjCmPHlFkV1IMrDjEHlDPWczz rlG0fbO2nOh5DTvGxrLGwrW5cE+okviJuR71VtbFSw9/tahpKGZBDpl7szqrAIGvHAs+ SAbY2VqXK5vVEixTkGXewNrMk+LM93LfNApnZQHmrimBXpVCEEe1uL7pBXsv3v/ZJiNC gxDwnJk0DRpDwiqEaTsK19iCIXxcttEB64xdgY2VGNQH1oRHqSXzUS/QdzVYXAtO24Tv nLGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781205655; x=1781810455; 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=S1MsXvm+zBkz9lw3HlzxpjF1MBFOX2jvGbB1/7ITdk4=; b=r/gStfENLQKLyhmb5aFugBSNGBFtQ9RSKLXTsgbwUzAdNVBVZnsLFKp2Yog3NKvDKL 0a6TqvzNpAav1N3dAKWNPT6MH+aWTpt9MvaXEZ2veWrN/6shejtRM3vmZg841ptvU/gH rUx9IvzhzQVGnhVi5m54AXGw5aJEq4IN6hk/TZJQ1B7l5BZ6ThBq2sXAivAkhoujDszo t54MHqcUa450uxA9L5nhc6CQ7XR9Ca2xFJduV2ijDGOzRYUCWxo2Sa8LQkjYaF59ioOt 9Jft10GO7VWtoTmbKSQ/mF8S2dvLapbjp/JxDzlY2rAii8SnxA+KYRIkte1Cm+cJw3zV VnRA== X-Forwarded-Encrypted: i=1; AFNElJ/Q6Ca9/rpyysCHRxH7ddKWGVCsaSZN8LdvWtpObm68MKvOnjn/ZytNpk0rkkYUTDVdmfaNsKI43hSF7w8I@lists.postgresql.org X-Gm-Message-State: AOJu0YzDE9caV8Q97PA/NQICmlp5yYvRynDLFRMs6wmCKMhd+TyizMCi frpXI6gO4xZl2roBs+6GD+978oCuMK3zrimMRDnqoIMPSMkf4vzalzXYHAuqPBLLAEhxpM98b6v dh+sYAcdnNDyC2e3feOQvpBAL/fyEsds= X-Gm-Gg: Acq92OGeEhPLefEOb/NZtBVy1BGuXFHUtYajNCgdaEeeFk4lET2BTKT+Rqxqy3thdnO wLXRfgEcleL99hVg/Weef35emfYQ+e6C9WBCdmd2WtL+yuAPqttkY7c1Bsvou0fC+5udO2gEdwH f2ZGU2FrQbQak0wPAxcWaKpwlcKEW114E5slN2/irfePwggG2kMEhKfCeWw0KnC7+5LcyA34puN ZCegNnfEzzb2HPvs+UtEJXICacFJ04FrssTIwyLPzjt23eFhyERTJCMCQ5FrtN/x1GAvWoA5cYF Tp3cHKL3aoIGwpBO6dpMCZ02jymsxAbcZnguKF74v1G1Gfe6kb8= X-Received: by 2002:a05:6a20:d808:b0:3b3:bf7f:efeb with SMTP id adf61e73a8af0-3b5e34377aamr4903265637.45.1781205655268; Thu, 11 Jun 2026 12:20:55 -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: Thu, 11 Jun 2026 12:20:17 -0700 X-Gm-Features: AVVi8CdY3nzmLerjgOQj9xniiVtMo2bZrUrOY9OuyXI0wkyK0ASeJl2XuAIvx1A 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 Wed, May 27, 2026 at 6:01=E2=80=AFPM Baji Shaik w= rote: > > Hello Masahiko, > > On Wed, May 27, 2026 at 7:02=E2=80=AFPM Masahiko Sawada wrote: >> >> I guess it would be safer to raise an error in such cases rather than >> silently allowing wraparound. Otherwise, users might only realize that >> their UUIDv7 values are no longer sortable years down the road, which >> would be disastrous. Moreover, raising an error would be consistent >> with how PostgreSQL natively handles timestamp + interval overflows. > > > +1. I ran into the same issue while testing, specifically, > uuidv7('infinity'::interval) overflows int64 during the epoch > conversion and produces a UUID with an incorrect timestamp. > There's no valid use case for infinity as a shift offset. Yeah, I think we should reject such cases at least. > I have a small patch that adds a TIMESTAMP_NOT_FINITE check after > timestamptz_pl_interval(), which catches both infinity and > -infinity. Happy to extend it to also cover the 48-bit upper/lower > bound checks if we agree on the direction. I think we should go ahead and add both upper and lower bound checks, barring objections. The current behavior silently produces UUIDs with nonsensical timestamps when the interval causes the result to go before the Unix epoch or beyond what 48 bits can represent. Regarding backward compatibility: this change would affect applications using uuidv7(interval) with values that cause the resulting timestamp to fall outside the representable range. But I guess that in practice, any such application is likely already getting incorrect results due to wraparound, so the risk of breaking working use cases seems very low. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com