From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Francisco Olarte <folarte@peoplecall.com>
Cc: Chuck Martin <clmartin@theombudsman.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Query not producing expected result
Date: Wed, 1 May 2019 11:13:57 -0700
Message-ID: <1e416a02-099f-004b-aaeb-0521cd03e6bf@aklaver.com> (raw)
In-Reply-To: <CA+bJJbzPv+Wa1CqhOm8ZtV8ZN6z2=OAF1wR=bB8xm0wXyR9QrA@mail.gmail.com>
References: <CAFw6=U2AisghJ2cOPOWopmk3NVVJ-WcSTNM+6K_-kQVBGxzMaA@mail.gmail.com>
<25696.1556728884@sss.pgh.pa.us>
<CAFw6=U3wV3NDt3c8sqHiE4QLRufy3s8d21BaLdkRLpPNUEh9ww@mail.gmail.com>
<CA+bJJbyXzdBL7198YsJTjyWjtrZbrkfiw9w=cxERhQnZ=j8bww@mail.gmail.com>
<f677424a-5902-63f2-608d-8b86412375c9@aklaver.com>
<CAFw6=U3iPjbDykpPeuG09RHTrdhdUN-OMHksxmVwukzuL3dbZw@mail.gmail.com>
<CA+bJJbxgDjLxQ9Mx8ipz29WT6_nfhbrh9+7gP0nZz4siBc29QQ@mail.gmail.com>
<f7baf914-c756-e7b9-6afb-dce6beef014c@aklaver.com>
<CA+bJJbzPv+Wa1CqhOm8ZtV8ZN6z2=OAF1wR=bB8xm0wXyR9QrA@mail.gmail.com>
On 5/1/19 11:04 AM, Francisco Olarte wrote:
> Adrian:
>
> On Wed, May 1, 2019 at 7:57 PM Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>> You will have to explain further as I am not seeing it:
>> test_(postgres)# select '2019-05-01 9:52' <= '2019-05-01 24:00'::timestamp;
>> ?column?
>> ----------
>> t
>>
>> test_(postgres)# select '2019-05-01 24:00' <= '2019-05-01 24:00'::timestamp;
>> ?column?
>> ----------
>> t
>
> Because you are using two selected examples. The one with 9:52 is ok.
>
> The last one is misleading because you are using a constant for a
> particular timestamp in MAY THE SECOND wich can be written to look
> like it is in MAY THE FIRST.
>
> Rewrite it as
> select '2019-05-02'::timestamp <= '2019-05-01 24:00'::timestamp;
>
> And you'll see and out of range date selected.
Technically it is correct as:
test_(postgres)# select '2019-05-02'::timestamp;
timestamp
---------------------
2019-05-02 00:00:00
which is Midnight and is both the end of one day and start of another.
It comes down to where you want to draw the line between days.
>
> This is why <= AND 24:00 are bad and misleading.
>
> You may not have problems with 00:00:00 times, but work a bit billing
> phone calls and you'll find about one in 86400 hit it ( more in my
> case as traffic distribution is skewed ). Use that kind of condition
> and you end up chasing why the monthly report has a dozen less calls
> than the sum of the daily ones the billing guys made using excel.
>
> Francisco Olarte.
>
--
Adrian Klaver
adrian.klaver@aklaver.com
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: adrian.klaver@aklaver.com, folarte@peoplecall.com, clmartin@theombudsman.com
Subject: Re: Query not producing expected result
In-Reply-To: <1e416a02-099f-004b-aaeb-0521cd03e6bf@aklaver.com>
References: <CAFw6=U2AisghJ2cOPOWopmk3NVVJ-WcSTNM+6K_-kQVBGxzMaA@mail.gmail.com> <25696.1556728884@sss.pgh.pa.us> <CAFw6=U3wV3NDt3c8sqHiE4QLRufy3s8d21BaLdkRLpPNUEh9ww@mail.gmail.com> <CA+bJJbyXzdBL7198YsJTjyWjtrZbrkfiw9w=cxERhQnZ=j8bww@mail.gmail.com> <f677424a-5902-63f2-608d-8b86412375c9@aklaver.com> <CAFw6=U3iPjbDykpPeuG09RHTrdhdUN-OMHksxmVwukzuL3dbZw@mail.gmail.com> <CA+bJJbxgDjLxQ9Mx8ipz29WT6_nfhbrh9+7gP0nZz4siBc29QQ@mail.gmail.com> <f7baf914-c756-e7b9-6afb-dce6beef014c@aklaver.com> <CA+bJJbzPv+Wa1CqhOm8ZtV8ZN6z2=OAF1wR=bB8xm0wXyR9QrA@mail.gmail.com> <1e416a02-099f-004b-aaeb-0521cd03e6bf@aklaver.com>
* 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