Recently I've been informed by a StackOverflow user that using BETWEEN
operator with values of data type timestamp without time zone
should not be used. Below is the quote.
Between means >= and <= and shall not be used with ranges that contain timestamps.
When asked for an explanation of this thesis or a link to Postgres documentation where it states that I've got an answer saying
Why would such a simple thing need a site with documentation. I am sure you can find many anyway if you google (at least my detailed posts on various forums demonstrating the case)
Well I googled. And found nothing that would advise against using this operator with timestamp values. In fact this answer on SO uses them and so does this mailing group post.
I was informed that all these years I was doing it wrong. Is it really the case?
As far as I know Postgres max precision for a timestamp is 1 microsecond
- correct me if I'm wrong. Thus aren't below statements equivalent ?
sample_date BETWEEN x AND y::timestamp - INTERVAL '1 microsecond'
and
sample_date >= x AND sample_date < y
Edit: The sample is just a consideration of the difference. I'm aware of the fact that developers can miss the time part, but assuming one knows how it behaves, why should it not be used? Generally speaking, this is merely a sample, but I'm wondering about the bigger scope. I've been investigating the planner and it seems to be parsing BETWEEN
to >= AND <=
.
Why does one preferably write >= AND <=
than BETWEEN
in the matter of results - not including the time to translate it?