Postgresql error

SELECT extract(MONTH
FROM ‘{{ date.start }}’ - INTERVAL '1 MONTH ')
FROM orders
WHERE date(created_at) BETWEEN ‘{{ date.start }}’ AND ‘{{ date.end }}’

when i run this query i get this error
Error running query: invalid input syntax for type interval: “2019-11-01” LINE 8: FROM ‘2019-11-01’ - INTERVAL '1 MONTH … ^

how to solve it , thanks

This is more of a Postgres question than a Redash one. The problem is you can’t extract a MONTH from a string value. Cast date.start and it will work:

SELECT extract(MONTH
FROM ‘{{ date.start }}’::timestamp - INTERVAL '1 MONTH ')
FROM orders
WHERE date(created_at) BETWEEN ‘{{ date.start }}’ AND ‘{{ date.end }}’
1 Like