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?

已提问 1 年前1966 查看次数
1 回答
0
已接受的回答

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
支持工程师
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容