pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ron <ronljohnsonjr@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: where clauses including timstamptz and intervals
Date: Fri, 09 Apr 2021 12:23:12 -0400
Message-ID: <2198582.1617985392@sss.pgh.pa.us> (raw)
In-Reply-To: <21887e8a-a9aa-d858-8c78-0a97a44c800a@gmail.com>
References: <df95450aee764d6fbedaf04613d17508@dst.dk>
	<20210409102400.GA2310@depesz.com>
	<21887e8a-a9aa-d858-8c78-0a97a44c800a@gmail.com>

Ron <ronljohnsonjr@gmail.com> 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?        │      timestamptz
>> ────────────────────────┼────────────────────────
>>  2020-11-01 02:00:00+01 │ 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.  Whether or not October 
> is 744 hours (31 days x 24 hours/day) or 743 hours (subtracting the "fall 
> 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=# set timezone = 'Europe/Paris';
SET
regression=# select '2020-10-01 00:00:00+00'::timestamptz;
      timestamptz       
------------------------
 2020-10-01 02:00:00+02
(1 row)

regression=# 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





view thread (6+ messages)  latest in thread

Message-ID: <2198582.1617985392@sss.pgh.pa.us>
Permalink:  ../2198582.1617985392@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2198582.1617985392@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ronljohnsonjr@gmail.com
  Subject: Re: where clauses including timstamptz and intervals
  In-Reply-To: <2198582.1617985392@sss.pgh.pa.us>
  References: <df95450aee764d6fbedaf04613d17508@dst.dk> <20210409102400.GA2310@depesz.com> <21887e8a-a9aa-d858-8c78-0a97a44c800a@gmail.com> <2198582.1617985392@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox