Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lUtuf-0002Wu-KS for pgsql-general@arkaria.postgresql.org; Fri, 09 Apr 2021 16:23:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lUtue-0008QQ-8g for pgsql-general@arkaria.postgresql.org; Fri, 09 Apr 2021 16:23:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lUtue-0008QJ-1O for pgsql-general@lists.postgresql.org; Fri, 09 Apr 2021 16:23:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lUtuc-0001TW-3d for pgsql-general@lists.postgresql.org; Fri, 09 Apr 2021 16:23:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 139GNCuN2198583; Fri, 9 Apr 2021 12:23:12 -0400 From: Tom Lane To: Ron cc: pgsql-general@lists.postgresql.org Subject: Re: where clauses including timstamptz and intervals In-reply-to: <21887e8a-a9aa-d858-8c78-0a97a44c800a@gmail.com> References: <20210409102400.GA2310@depesz.com> <21887e8a-a9aa-d858-8c78-0a97a44c800a@gmail.com> Comments: In-reply-to Ron message dated "Fri, 09 Apr 2021 10:52:47 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2198581.1617985392.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 09 Apr 2021 12:23:12 -0400 Message-ID: <2198582.1617985392@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ron writes: > On 4/9/21 5:24 AM, hubert depesz lubaczewski wrote: >> For example, in my timezone: >> = >> $ select ('2020-10-01 00:00:00+00'::timestamptz + interval '1 month'), = '2020-11-01 00:00:00+00'::timestamptz; >> ?column? =E2=94=82 timestamptz >> =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 >> 2020-11-01 02:00:00+01 =E2=94=82 2020-11-01 01:00:00+01 >> (1 row) >> = >> Please note that there is 1 hour difference. >> The reason is that somewhere in there we change time due to daylight >> savings. > That looks like a flaw in how "month" is calculated.=C2=A0 Whether or no= t October = > is 744 hours (31 days x 24 hours/day) or 743 hours (subtracting the "fal= l = > back" hour), one month from 01-Oct-2020 is still 01-Nov-2020. No, it's more likely because the calculation was done in some time zone other than UTC, which (somewhat confusingly) is what the starting value was specified in. Assuming Hubert meant EU rules, we have regression=3D# set timezone =3D 'Europe/Paris'; SET regression=3D# select '2020-10-01 00:00:00+00'::timestamptz; timestamptz = ------------------------ 2020-10-01 02:00:00+02 (1 row) regression=3D# select '2020-10-01 00:00:00+00'::timestamptz + interval '1 = month'; ?column? = ------------------------ 2020-11-01 02:00:00+01 (1 row) which looks to me like the addition did exactly what it's supposed to, ie same local time 1 month later. regards, tom lane