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 1vNcT8-008nXZ-0G for pgsql-general@arkaria.postgresql.org; Mon, 24 Nov 2025 19:43:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vNcT6-003e1P-1W for pgsql-general@arkaria.postgresql.org; Mon, 24 Nov 2025 19:43:24 +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 1vNcT6-003e1H-0F for pgsql-general@lists.postgresql.org; Mon, 24 Nov 2025 19:43:24 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vNcT4-001HiB-0J for pgsql-general@postgresql.org; Mon, 24 Nov 2025 19:43:24 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7bab7c997eeso5151072b3a.0 for ; Mon, 24 Nov 2025 11:43:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pinpointresearch.com; s=google; t=1764013399; x=1764618199; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=dzL7SvDZcp+PFVSbCyHmeYXMVGYkbaI4L3A7VyiSHuc=; b=rhZow8oAQP9rlJiBwgXz7ridcfTiP05wIdbMeRHe8nsVnVDJTuF5I9mT0CpJOwtgvK ajIWdtJGAop6OxPAYiG1z3bApWAUbu8PvlLs0K0HJm37GLKr3+WQtwViK9ON/JiwuIIp wEdMe+nQ6Pd1M5+0eDhmkzG4all9uxMhNWVz4EQmGPreUBWm/1Ybnfm2Snsqf8ZGGNVN q7Cl8tpfGtyOFGzzwi/XT3ZqgMa9rqp9FlC3NI6joJ0oa9VO3eKzGs2K1q3mVmYWupAA V0lYmNRgyWSoVWy9fpSbsCLjxApf2I57RUG3jditaLvRTwDB36xo8cTkrZvptkM6H96n mJ8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764013399; x=1764618199; h=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=dzL7SvDZcp+PFVSbCyHmeYXMVGYkbaI4L3A7VyiSHuc=; b=A7FyrLAK14tpNalge+8NZBkuHN8bFCWu89WF0M25haxn26r6XrUqh9qLFGK7d/fu4w 0QkjlbI+xTpSI1/qDEX8W9uOWS1wKbTPwzJsP0JbSOBOObqmD6e7WYiuQ89TG/sCEQ8G LNlZ8ifBRlnQNPP42k16DfA4khXN+RVyzCSIi72bWbkvyp3os9P6qlTwLDa3bJ6W/San Qs7uiX0pEFkTSIWSEExsCttkblbvuFmnui9rIgq7r6cIWCtq4YYMq8TT7M/B8vnRUkh1 nDF7IsdnxqRsHmXHvLLmsgnCu9f0xpgKzmzW0HMGZVWVBOvm7nhIB//2r2Rhnyh+/e8t +qxA== X-Forwarded-Encrypted: i=1; AJvYcCV+fhCxp/eHy+wkzCk7QDuq1fG51WvTDBlKBycHiXUDTrEwOGQ1GuXk3MhPWdfz9OFu6lok2ebXhpCisL2f@postgresql.org X-Gm-Message-State: AOJu0YyJzI9nMq2FM21MFQypjHsM0u6J+Fdpu214pRwA80zUFE2Me0vQ HC0Gdw6TXOt5qHXDuNwETttLlowi/vXXauIogpMzOMelp+7ihFB6RjYXoOfBT7AX1yn50dg7sFQ 85UOEFVvuRL2Ofm19dg7oGfPIEfHBfTERTes1SvtPSQ== X-Gm-Gg: ASbGncv0blCoBK64wCd2+xIpGWaZk86uEf+nJ6aPHbeWaVbUVLDdl95kvXnGC6D0o31 0Iyuq5emv9kosxPmiJcI/btC049CyjlUtFfMjKnoUbBo+zrPTnfykbJa68Aos7cHcgftrgFWiDc meYVhHgUnCeTrcv0mOSq1CW3gkHgrYTr651upiCEeYQSIVBOjYxsLBHYCowv3iMRY5gSOP/uwLr fBVWrbnnJLiYpS2gMK/1cW57QSHEasNUfgRS/QSEUy5O0VvU9/11vAj4QQ5Cc45GhdL9HPk45D7 u9adCu8= X-Google-Smtp-Source: AGHT+IE2V08ghmXKUVgDPnzlIiGgSpJqcob78OAWcLDQN9chwOl5fiiC+xNumS67QFHDHt6Vr4AhkCes9yPLABYobIY= X-Received: by 2002:a05:7022:b882:b0:11b:bf3f:5251 with SMTP id a92af1059eb24-11c9d718e3bmr6364812c88.16.1764013399298; Mon, 24 Nov 2025 11:43:19 -0800 (PST) MIME-Version: 1.0 References: <2e2a34695d84a297e62a2996466fecf97005a2fb.camel@cybertec.at> <2555134.1763772908@sss.pgh.pa.us> In-Reply-To: <2555134.1763772908@sss.pgh.pa.us> From: Steve Crawford Date: Mon, 24 Nov 2025 11:43:07 -0800 X-Gm-Features: AWmQ_bmPYXADB1Yih_8OdW0uBEamIVFeF4yNCcCZK9sZvjE3Nmm1bGg_5PT2UUE Message-ID: Subject: Re: Unexpected date conversion results To: Tom Lane Cc: Laurenz Albe , Adrian Klaver , PG-General Mailing List Content-Type: multipart/alternative; boundary="0000000000000b65c706445c60fd" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000000b65c706445c60fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Nov 21, 2025 at 4:55=E2=80=AFPM Tom Lane wrote: > Laurenz Albe writes: > > I dug into the git history, and it has been like that since commit > b3506006b564 > > in 2002 (way before version 9.x). That commit fixed a bug that returne= d > ten > > time the correct reault (but still offset from the UTC epoch). > > I didn't bisect, but I get this in 9.1.24: > > regression=3D# set timezone =3D 'America/Los_Angeles'; > SET > regression=3D# select to_timestamp(extract(epoch from current_date)); > to_timestamp > ------------------------ > 2025-11-21 00:00:00-08 > (1 row) > > and this in 9.2.24: > > regression=3D# set timezone =3D 'America/Los_Angeles'; > SET > regression=3D# select to_timestamp(extract(epoch from current_date)); > to_timestamp > ------------------------ > 2025-11-20 16:00:00-08 > (1 row) > > regards, tom lane > I guess this reveals the age of the bit of code I was resurrecting, he says while pulling out his Pg 8.4 release t-shirt. :) After much more digging I found the relevant remark way back in the 9.2 release notes (https://www.postgresql.org/docs/release/9.2.0/): Make EXTRACT(EPOCH FROM timestamp without time zone) measure the epoch from local midnight, not UTC midnight (Tom Lane) This change reverts an ill-considered change made in release 7.3. Measuring from UTC midnight was inconsistent because it made the result dependent on the timezone setting, which computations for timestamp without time zone should not be. The previous behavior remains available by casting the input value to timestamp with time zone. Sorry for the goose chase. -Steve --0000000000000b65c706445c60fd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Fri, Nov 21, 202= 5 at 4:55=E2=80=AFPM Tom Lane <tgl@= sss.pgh.pa.us> wrote:
Laurenz Albe <laurenz.albe@cybertec.at> writes:
> I dug into the git history, and it has been like that since commit b35= 06006b564
> in 2002 (way before version 9.x).=C2=A0 That commit fixed a bug that r= eturned ten
> time the correct reault (but still offset from the UTC epoch).

I didn't bisect, but I get this in 9.1.24:

regression=3D# set timezone =3D 'America/Los_Angeles';
SET
regression=3D# select to_timestamp(extract(epoch from current_date));
=C2=A0 =C2=A0 =C2=A0 to_timestamp=C2=A0 =C2=A0 =C2=A0
------------------------
=C2=A02025-11-21 00:00:00-08
(1 row)

and this in 9.2.24:

regression=3D# set timezone =3D 'America/Los_Angeles';
SET
regression=3D# select to_timestamp(extract(epoch from current_date));
=C2=A0 =C2=A0 =C2=A0 to_timestamp=C2=A0 =C2=A0 =C2=A0
------------------------
=C2=A02025-11-20 16:00:00-08
(1 row)

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane

I guess th= is reveals the age of the bit of code I was resurrecting, he says while pul= ling out his Pg 8.4 release t-shirt. :)=C2=A0

Afte= r much more digging I found the relevant remark way back in the 9.2 release= notes (https://= www.postgresql.org/docs/release/9.2.0/):

Make EXTRACT(EPOCH FROM timestamp wi= thout time zone) measure the epoch from local midnight, not UTC midnight (T= om Lane)

This= change reverts an ill-considered change made in release 7.3. Measuring fro= m UTC midnight was inconsistent because it made the result dependent on the= timezone setting, which computations for timestamp without time zone shoul= d not be. The previous behavior remains available by casting the input valu= e to timestamp with time zone.

= Sorry for the goose chase.

-Steve

--0000000000000b65c706445c60fd--