Skip to content

AWS query issue

0

select * from wslrisrmart.risr_monthly where month_yr between '2024-01-01' and '2024-12-31';

I want complete data of 2024 from wslrisrmart.risr_monthly and I have used above query and it's throwing error, can anyone help please?

asked 2 years ago158 views

1 Answer
1
Accepted Answer

The error you're encountering is likely due to a type mismatch between the 'month_yr' column in your table and the string literals you're using in the BETWEEN clause. To resolve this issue, you need to ensure that both sides of the comparison are of the same data type.

Assuming that 'month_yr' is a DATE type column, you can modify your query as follows:

SELECT * FROM wslrisrmart.risr_monthly 
WHERE month_yr BETWEEN DATE '2024-01-01' AND DATE '2024-12-31';

By using the DATE keyword before the string literals, you're explicitly telling the database to treat these strings as date values. This should resolve any type mismatch errors.

If 'month_yr' is stored as a string in your table, you might need to cast it to a DATE type for comparison:

SELECT * FROM wslrisrmart.risr_monthly 
WHERE CAST(month_yr AS DATE) BETWEEN DATE '2024-01-01' AND DATE '2024-12-31';

Additionally, make sure that the 'month_yr' column in your table actually contains date values for 2024. If the data for 2024 doesn't exist yet, your query will return an empty result set, but it shouldn't throw an error.

If you're still encountering issues, it would be helpful to know the exact error message you're receiving and the data type of the 'month_yr' column in your table.
Sources
TYPE_MISMATCH: line 3:32: Cannot apply operator: date < varchar(10) | AWS re:Post

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.