SQL greater than or equal to does not work with DATE on Amazon Athena

0

I have a table on Amazon Athena and one of the columns is "sessiondate" whose data type is varchar.

Column1Column2sessiondate
Data1Data62022-06-27
Data2Data72022-06-27
Data3Data82022-07-25
Data4Data92022-12-19
Data5Data122023-01-11

I've used the following SQL query for almost 6 months until last night (4/13 10PM).

Since last night, the SQL query errors out complaining '>=' cannot be applied to varchar, date

SELECT * FROM MyDatabase.MyTable
WHERE sessiondate >= DATE('2022-12-18')

Enter image description here

Does anyone know why the greater than or equal to symbol does not work anymore?

asked a year ago1867 views
1 Answer
0
Accepted Answer

Hello,

To understand your issue better, I tried to reproduce the issue referring your above mentioned schema. I created a table with above value and a date column with data type is varchar.

I was getting the same error with Athena engine version 2 and as well as 3:

 '>=' cannot be applied to varchar

Then I tried to run the query by removing 'DATE' from sql and it got successful.

Additionally, You can query in the below format, I have tested at my end and it is working fine.

SELECT * FROM MyDatabase.MyTable WHERE sessiondate >= ('2022-12-18')

SELECT * FROM MyDatabase.MyTable WHERE cast(sessiondate as date) >= date('2022-12-18')

We are unable to provide you the root cause why your query was working fine earlier as we need to check your query logs, meanwhile please check if there is any new data of different type is added recently in your date column.

Or check if there is any change in query execution like Athena version 2 or 3 being used, IAM role or any IAM permissions etc, or if there is any change in schema of 'sessiondate' column.

You can check and confirm the column schema from Glue or Athena console.

For further investigation and to find the root cause of the issue , we require details that are non-public information. Please open a support case with AWS using the following

https://support.console.aws.amazon.com/support/home#/case/create

profile pictureAWS
SUPPORT ENGINEER
answered a year 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.

Guidelines for Answering Questions