sqlpalantir-foundryfoundry-slate

How do I make a query calling from and to date values from date range picker?


I am trying to filter a table on slate by doing this query

SELECT *
from "foundry_sync"."master_dataset" 
WHERE event_date >= ( {{w_date_range_picker.fromDateValue}} ) 
AND event_date <= ( {{w_date_range_picker.toDateValue}} ) 

But I am getting the error

  Hint: No operator matches the given name and argument types. You might need to add explicit type casts.

Any idea on how to make such a call?


Solution

  • A date picker value has this format: 2023-03-14.

    If you click on the "Preview Rendered Query" button (little icon looking like an eye in the bottom right corner of your query window) you will see that when rendering a query it will be placed in that literal format into the query. Sql will then process that as an arithmetic operation and evaluate it into a number.

    To avoid that you will need to add ' ' around the date picker value. Additionally you will have to wrap the column name into " ". That transforms your query into:

    SELECT *
    from "foundry_sync"."master_dataset" 
    WHERE "event_date" >= ( '{{w_date_range_picker.fromDateValue}}' ) 
    AND "event_date" <= ( '{{w_date_range_picker.toDateValue}}' )
    

    If this doesn't fix your problem you can add explicit casting: CAST ('value' AS DATE) or CAST ("column_name" AS DATE)