I have a table for matches. The table has a column named matchdate, which is a datetime field.
If I have 3 matches on 2011-12-01:
- 2011-12-01 12:00:00
- 2011-12-01 13:25:00
- 2011-12-01 16:00:00
How do I query that? How do I query all matches on 1 single date?
I have looked at date_trunc(), to_char(), etc.
Isn’t there some "select * where datetime in date" function?
Cast your
timestampvalue todateif you want simple syntax. Like this:However, with big tables this will be faster:
Reason: the second query does not have to transform every single value in the table and can utilize a simple index on the timestamp column. The expression is sargable.
Note excluded the upper bound (
<instead of<=) for a correct selection.You can make up for that by creating an index on an expression like this:
Then the first version of the query will be as fast as it gets.