Search code examples
sqlprestotrino

Trino - How do I filter on dates


Just started to use Salesforce and I'm using DBeaver to query the data.

I've been using MSSQL for 15 years but this is my first time using Trino SQL and running into issues when doing the most basic things like filtering on dates.

All I want to do is a simple SELECT between a date range.

I've tried all sorts of different things and documentation I've found doesn't answer this basic question.

enter image description here


Solution

  • To filter on dates you need dates on both sides of the comparison. '2024-04-25 21:27:20.547 UTC' is not a date literal and would not be converted to one in Trino. If the CreatedDate_C column is of date/timestamp type (can be checked with select typeof(CreatedDate_C)) then the following should work:

    WHERE CreatedDate_C > timestamp '2024-04-25 21:27:20.547 UTC'; -- or date '2024-04-25' 
    

    or

    WHERE CreatedDate_C BETWEEN timestamp '2024-04-25 21:27:20.547 UTC' 
       AND timestamp '2025-04-25 21:27:20.547 UTC';
    

    If CreatedDate_C is not date/timestamp then you will need to cast it or parse it to one.