8

I am trying to use Athena to query some data I have stored in an s3 bucket in parquet format. I have field called datetime which is defined as a date data type in my AWS Glue Data Catalog. Image showing schema details in Data Catalog

When I try running the following query in Athena, I get the error below:

SELECT DISTINCT datetime 
FROM "craigslist"."pq_craigslist_rental_data_parquet"
WHERE datetime > '2018-09-14'
ORDER BY datetime DESC;

And the error:

Your query has the following error(s):

SYNTAX_ERROR: line 3:16: '>' cannot be applied to date, varchar(10)

What am I doing wrong here? How can I properly filter this data by date?

4 Answers 4

8

the string literal that you provide has to be casted to a date, in order to compare to a date.

where datetime = date('2019-11-27')

Sign up to request clarification or add additional context in comments.

Comments

2

its having issue with the string literal used for date filter. Use WHERE datetime > date '2018-09-14'

3 Comments

Right, but any ideas what the actual problem is or how to fix it?
looks like implicit date conversion is not working as expected. Most of the time, the conversion to string to float or vice versa happens automatically, hence its called implicit. But in some cases, it can't do it. For those cases, we need to help the interpreter explicitly.
Unfortunately that didn't work either. Still got: SYNTAX_ERROR: line 2:16: '>' cannot be applied to varchar, date
1

from_iso8601_date or date should work.

SELECT DISTINCT datetime 
FROM "craigslist"."pq_craigslist_rental_data_parquet"
WHERE datetime > from_iso8601_date('2018-09-14')
ORDER BY datetime DESC;

both return a proper date object.

SELECT typeof(from_iso8601_date('2018-09-14'))

enter image description here

Comments

0

Bit late here, but I had the same issue and the only workaround I have found is:

WHERE datetime > (select date '2018-09-14')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.