From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Query not producing expected result
Date: Wed, 1 May 2019 12:05:57 -0500
Message-ID: <105c087b-71a1-b26a-1453-8320e8318a03@gmail.com> (raw)
In-Reply-To: <CAOBaU_YZm-0cP-FwdhpTfabGhA0M=-nVy+jtX44R05NLAWEL1A@mail.gmail.com>
References: <CAFw6=U2AisghJ2cOPOWopmk3NVVJ-WcSTNM+6K_-kQVBGxzMaA@mail.gmail.com>
<CAOBaU_YZm-0cP-FwdhpTfabGhA0M=-nVy+jtX44R05NLAWEL1A@mail.gmail.com>
On 5/1/19 11:39 AM, Julien Rouhaud wrote:
> On Wed, May 1, 2019 at 6:27 PM Chuck Martin <clmartin@theombudsman.com> wrote:
>> I need help figuring out why a query is not returning the records I expect it to. I'm searching on a DateTime column (timestamp without time zone - not nullable). The query includes:
>>
>> AND event.Primaryresp_fkey = 5000011 AND event.DateTime <= 'May-1-2019' AND event.EventDone < 1
>>
>> This does not return a record that has a DateTime value "May 1, 2019 9:52 AM". If I modify the query to:
>>
>> AND event.Primaryresp_fkey = 5000011 AND event.DateTime <= 'May-2-2019' AND event.EventDone < 1
>>
>> it does return the record in question. I assume I am not doing the data comparison correctly, but don't know why.
> That's because it's using a timestamp comparison, not a date
> comparison. So 'May-1-2019' is casted to timestamp, which gives
> 2019-05-01 00:00:00.
>
> If you want a comparison based on date instead of timestamp , you have
> to ask to it explicitly. For instance: event.DateTime*::date* <=
> 'May-1-2019'
Wouldn't that stop the query planner from using any index on event.DateTime?
--
Angular momentum makes the world go 'round.
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: ronljohnsonjr@gmail.com
Subject: Re: Query not producing expected result
In-Reply-To: <105c087b-71a1-b26a-1453-8320e8318a03@gmail.com>
References: <CAFw6=U2AisghJ2cOPOWopmk3NVVJ-WcSTNM+6K_-kQVBGxzMaA@mail.gmail.com> <CAOBaU_YZm-0cP-FwdhpTfabGhA0M=-nVy+jtX44R05NLAWEL1A@mail.gmail.com> <105c087b-71a1-b26a-1453-8320e8318a03@gmail.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