- Newest
- Most votes
- Most comments
As far as I know, both AWS Glue and Amazon Athena do not natively support timestamp precision beyond milliseconds, i.e., they do not support microseconds or nanoseconds.
Timestamps in AWS Glue and Athena are represented in the YYYY-MM-DD HH:MI:SS.fff
format (down to milliseconds precision) as you've noted. This is a limitation of the current timestamp data type in these services. You can read more about the supported data types in the official documentation: Data types in Amazon Athena
There are a couple of possible workarounds, but they are not perfect and may require additional data manipulation:
-
String Field: Store your timestamps as a string field with your desired precision in your Parquet files. You can then convert or manipulate these strings in your Athena queries as needed.
You could use the string format
YYYY-MM-DD hh:mm:ss.ffffff
and cast it as a timestamp when necessary in your Athena queries:SELECT DATE_PARSE(your_timestamp_string, '%Y-%m-%d %H:%i:%s.%f') FROM your_table
Keep in mind that this will still truncate your timestamp to milliseconds when casting it as a timestamp.
-
Separate Fields: Another approach is to separate the date and time components and the fractional seconds into separate fields. This would allow you to maintain precision for your fractional seconds in a separate numeric field, although it would complicate date/time operations.
If this is a crucial requirement for your use case, I would recommend reaching out to AWS support or your AWS account manager to discuss possible solutions or to submit a feature request.
If the answer is helpful, please click "Accept Answer" and upvote it.
Thanks a million for your fast and precise answer. We will go for the first approach since it is the easiest and safest method in my opinion. We will discuss a feature request with our account manager.
Best regards, Susa
Relevant content
- Accepted Answerasked 5 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
Hi Susa, I’m happy to help. Please don’t forget to click on “Accept Answer” as that helps other members of the community find this article easily on search, and recognizes my effort to help other people with their AWS questions.