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?

demandé il y a un an2055 vues
1 réponse
0
Réponse acceptée

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
INGÉNIEUR EN ASSISTANCE TECHNIQUE
répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions