RE: Where condition doesn't work as expected

From: Ken Benson <Ken(at)infowerks(dot)com>
To: "pgsql-novice(at)lists(dot)postgresql(dot)org" <pgsql-novice(at)lists(dot)postgresql(dot)org>
Subject: RE: Where condition doesn't work as expected
Date: 2020-02-08 22:43:46
Message-ID: MWHPR19MB0096AB55D9A88E42CD8C8EC0A31F0@MWHPR19MB0096.namprd19.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Ken Benson | ken @ infowerks-dot-com

-----Original Message-----
From: William Colls <william(at)williamcollsassoc(dot)ca>
Sent: Saturday, February 8, 2020 2:40 PM
To: pgsql-novice(at)lists(dot)postgresql(dot)org
Subject: Where condition doesn't work as expected
>>>>-----Original Message-----
>>>>From: William Colls <william(at)williamcollsassoc(dot)ca>
>>>>Sent: Saturday, February 8, 2020 2:40 PM
>>>>To: pgsql-novice(at)lists(dot)postgresql(dot)org
>>>>Subject: Where condition doesn't work as expected
>>>>
>>>>I have the following condition a select statement:
>>>>
>>>> WHERE "datetime" > '2019-03-31 23:59:59'
>>>>
>>>>datetime is a character field with data in the format YYYY-MM-DD HH:MM:SS. However it returns any line where the datetime field begins with 2019. I suspect that I should be using timestamp values, but I can't figure out how to cast the datetime field value to a timestamp.
>>>>

[Ken.B]
SELECT to_date('20170103','YYYYMMDD');
https://www.postgresqltutorial.com/postgresql-to_date/

>>>>Thanks for your time.
>>>>
>>>>William.
>>>>
I have the following condition a select statement:

 WHERE "datetime" > '2019-03-31 23:59:59'

datetime is a character field with data in the format YYYY-MM-DD HH:MM:SS. However it returns any line where the datetime field begins with 2019. I suspect that I should be using timestamp values, but I can't figure out how to cast the datetime field value to a timestamp.

[Ken.B]
SELECT to_date('20170103','YYYYMMDD');
https://www.postgresqltutorial.com/postgresql-to_date/

Thanks for your time.

William.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Bzzzz 2020-02-08 23:18:55 Re: Where condition doesn't work as expected
Previous Message William Colls 2020-02-08 22:39:32 Where condition doesn't work as expected