0

I'm trying to get records which between two dates. Below is my query

select * from my_data 
where name = 'customer' AND 
(time between (('2021-03-24'::date - '1 month'::interval) AND '2021-03-24'::date))

However I'm getting a syntax error

ERROR:  syntax error at or near ")"
LINE 1: ...03-24'::date - '1 month'::interval) AND '2021-03-24'::date))
                                                                      ^

What is the correct way of writing the query to return rows 1 month older than a given date?

1 Answer 1

1

You can drop the parentheses:

select *
from my_data 
where name = 'customer' AND 
      time between '2021-03-24'::date - '1 month'::interval AND '2021-03-24'::date;

The specific issue is that the range for between does not accept parens.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.