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 1lUtRL-0001OU-MQ for pgsql-general@arkaria.postgresql.org; Fri, 09 Apr 2021 15:52:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lUtRI-0001vC-H2 for pgsql-general@arkaria.postgresql.org; Fri, 09 Apr 2021 15:52:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lUtRI-0001v5-6s for pgsql-general@lists.postgresql.org; Fri, 09 Apr 2021 15:52:56 +0000 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lUtRD-00025b-VG for pgsql-general@lists.postgresql.org; Fri, 09 Apr 2021 15:52:55 +0000 Received: by mail-oo1-xc2b.google.com with SMTP id r17-20020a4acb110000b02901b657f28cdcso1439232ooq.6 for ; Fri, 09 Apr 2021 08:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=N8qDFrcvQzddKkrOWT5uzxarK0gSJfliaah8B0s59bo=; b=QGUUaUWfY4JMSWvlByoGEtRmxaEMdCOlOhcWpSIq8O4LO17q0GytTmKp97TUGVJoIz I82U2K3dP7oA4fs0kNU423nXb3jYrnvoAnLbQQfZvejwG0wqD7bleh9EXoZzk0bB9zMp 2RQMlEfOkeEVqM5BLmag85Lf5a4Voir+L5uQCRktMDK1uk60LR4KQYE/A1h+mU+Yd7DJ eJvKFXxYOV7AP+ByKdXHaoAWwMTViiXs2s5mEpU3zNuORF4C+ZqWokKzQuju43/c1Rnj Y5YVC092ZNs0fCpySyhCjaA7ehzUbQKyzuXuG07SqG4JkIzyTg963XUbxNJ4Fa/aAe5n NqYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=N8qDFrcvQzddKkrOWT5uzxarK0gSJfliaah8B0s59bo=; b=ZPqfjiL37ljDyUqZCRejM40UUbOLXwR8pyzS9Pmw85CxukvxyJV2YC6zmEeySQ903Q w6DLo+mMy1BM3Du6a1hwPZOLL3DfiLbzcqtiG0RjALgDxWy9I9Dr2goaFNbrP6ncWCrQ iBY++oatTPiFBgF/3ZuWX1LzyXuqtsRnJsa23CaAX/VR1lVrWqbkywdcJ7IjX8dXMrUH TqzdZBPZFZHGPMbQQ8fjYt/2sLnJ4t+YWlL5nuEQbZzgXu8QmP2okTcQZWlcynCC1wEZ UxkpclINEDdiyBc15jBRWqbz+biUUphlMALwdx2rd9vqmFZbjXIP7KGe2nlLFRKvnMzK CBmg== X-Gm-Message-State: AOAM532n9wxZuw5UA0f7H/cGU1C3wS3Q2R0PF2LCVVircNm6PY921D7b WrUgCGufs/SE1VKL1A4WXVQTpDUXUwM= X-Google-Smtp-Source: ABdhPJzodE34uDEhZiugP8skgnBh1t21xVgD6WogqCaBNNtDvEgJ/9WlrRroVEoi/A3LPkzVRSeQgA== X-Received: by 2002:a4a:3c48:: with SMTP id p8mr12499891oof.79.1617983568772; Fri, 09 Apr 2021 08:52:48 -0700 (PDT) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id d13sm679743otk.74.2021.04.09.08.52.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Apr 2021 08:52:48 -0700 (PDT) Subject: Re: where clauses including timstamptz and intervals To: pgsql-general@lists.postgresql.org References: <20210409102400.GA2310@depesz.com> From: Ron Message-ID: <21887e8a-a9aa-d858-8c78-0a97a44c800a@gmail.com> Date: Fri, 9 Apr 2021 10:52:47 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210409102400.GA2310@depesz.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/9/21 5:24 AM, hubert depesz lubaczewski wrote: > On Fri, Apr 09, 2021 at 07:24:54AM +0000, Niels Jespersen wrote: >> Hello all >> >> Are these two queries exactly eqivalent? The table is partitioned on >> r_time, which is a timestamptz. The explain plans are not exactly the >> same. The first wants to scan a partition more than the latter. >> >> select f.xx from f >> where f.r_time >= '2020-10-01 00:00:00+00'::timestamptz >> and f.r_time < ('2020-10-01 00:00:00+00'::timestamptz + interval '1 month'); >> >> select f.xx from f >> where f.r_time >= '2020-10-01 00:00:00+00'::timestamptz >> and f.r_time < ('2020-11-01 00:00:00+00'::timestamptz); > It depends on timezone. > > 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. -- Angular momentum makes the world go 'round.