I have a table in AWS Athena having column named 'servertime' with the data type of timestamp. I run a query like this
select *
from table_name
where servertime between '2018-04-01 00:00:00' and '2018-04-05 23:59:59';
It gives me this error: Your query has the following error(s): SYNTAX_ERROR: line 1:41: '=' cannot be applied to timestamp, varchar(19)
How can I resolve this in Athena? And It's important query to get the data from this table.
The TIMESTAMP data in your table might be in the wrong format. Athena requires the Java TIMESTAMP format. Use Presto's date and time function or casting to convert the STRING to TIMESTAMP in the query filter condition. For more information, see Date and time functions and operators in the Presto documentation.
date – A date in ISO format, such as YYYY - MM - DD . For example, date '2008-09-15' . An exception is the OpenCSVSerDe, which uses the number of days elapsed since January 1, 1970.
Incorrect LOCATION path If the input LOCATION path is incorrect, then Athena returns zero records.
Athena accepts mixed case in DDL and DML queries, but lower cases the names when it executes the query. For this reason, avoid using mixed case for table or column names, and do not rely on casing alone in Athena to distinguish such names.
The problem you are seeing is related to your between condition. If you present the timestamp just as varchar, Athena will not convert those into timestamps.
For that to happen, you need to pass an explicit typecast.
select * from table_name
where servertime
between TIMESTAMP '2018-04-01 00:00:00'
and TIMESTAMP '2018-04-05 23:59:59';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With