public inbox for [email protected]
help / color / mirror / Atom feedFrom: Bzzzz <[email protected]>
To: William Colls <[email protected]>
Cc: [email protected]
Subject: Re: Where condition doesn't work as expected
Date: Sat, 8 Feb 2020 23:18:55 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
On Sat, 8 Feb 2020 17:39:32 -0500
William Colls <[email protected]> wrote:
> 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.
Depending on what you need, use either TIMESTAMP or TIMESTAMPTZ.
[…] WHERE (datetime::TIMESTAMP) > TIMESTAMP'2019-03-31 23:59:59' ;
(note that the TIMESTAMP to the right of the comparison is not
mandatory.)
As it costs, if you have no special reason for the "datetime" column to
dwell in text or varchar, you should consider converting it to a
TIMESTAMP or TIMESTAMPTZ type to avoid any conversion when querying.
Jean-Yves
view thread (4+ messages) latest in thread
reply
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Where condition doesn't work as expected
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox