Re: Query not producing expected result - Mailing list pgsql-general

From David G. Johnston
Subject Re: Query not producing expected result
Date
Msg-id CAKFQuwYH8-zkGPOPrE9zRQ_z_PPjS5db8i6Vw9iX_BLYaJn7vQ@mail.gmail.com
Whole thread Raw
In response to Query not producing expected result  (Chuck Martin <clmartin@theombudsman.com>)
List pgsql-general
On Wed, May 1, 2019 at 9:27 AM 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. 


The field is a timestamp - which means there is a time involved.  If you don't specify one explicitly that time is going to be midnight.  9:52AM on the 1st is after midnight on the 1st so the first query doesn't return the 9:52AM record.

IOW, the DateTime field remains as-is and the comparator is turned into a timestamp without time zone.

David J.

pgsql-general by date:

Previous
From: Julien Rouhaud
Date:
Subject: Re: Query not producing expected result
Next
From: Tom Lane
Date:
Subject: Re: Query not producing expected result