Dynamic query for date filtering

I was searching for a long time now to find a solution on how to create a query that will accept a variable.

I just want to add the daysFilter

AND "message_date" >= NOW() - INTERVAL '{{ daysFilter.value || 7 }} days'

to this query

SELECT
  *
FROM
  "xxx"
WHERE
  "yyy" >= {{ filter1.value || 1 }}
  AND "date" >= NOW() - INTERVAL '{{ daysFilter.value || 7 }} days'

but I get this error:

bind message supplies 2 parameters, but prepared statement "" requires 1

Hi @Mischa,

Have you tried this?

SELECT
  *
FROM
  "xxx"
WHERE
  "yyy" >= {{ filter1.value || 1 }}
  AND "date" >= NOW() - ({{ daysFilter.value || 7 }} * INTERVAL '1 DAY');

Awesome! Thanks you @Almopt :pray: