Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Athena and date_format

I have some issue while formatting a timestamp with Amazon Athena service.

select date_format(current_timestamp, 'y')

Returns just 'y' (the string).

The only way I found to format dates in Amazon Athena is trough CONCAT + YEAR + MONTH + DAY functions, like this:

select CONCAT(cast(year(current_timestamp) as varchar), '_', cast(day(current_timestamp) as varchar))

like image 738
emmekappa Avatar asked May 19 '17 08:05

emmekappa


People also ask

Can Athena be used for ETL?

We also found Athena to be a robust, powerful, reliable, scalable, and cost-effective ETL tool. The ability to schedule SQL statements, along with support for Create Table As Select (CTAS) and INSERT INTO statements, helped us accelerate our ETL workloads.

What is the difference between Athena and S3?

Conclusion : Athena can used for complex queries on the files, and span multiple folders under S3 bucket. S3 Select can used for simple queries based in a single object. Show activity on this post. S3 Select makes it easy to retrieve specific data from the contents of an object using simple SQL expressions.

What is AWS glue vs Athena?

AWS Athena vs AWS Glue A key difference between Glue and Athena is that Athena is primarily used as a query tool for analytics and Glue is more of a transformation and data movement tool. Creating tables for Glue to use in ETL jobs.

Is AWS Athena same as Presto?

Amazon Athena is an interactive query service that makes it easy to analyze data in Amazon S3 using standard SQL. Athena is serverless, so there is no infrastructure to manage, and you pay only for the queries that you run. On the other hand, Presto is detailed as "Distributed SQL Query Engine for Big Data".


1 Answers

select  current_timestamp

       ,date_format     (current_timestamp, '%Y_%m_%d')
       ,format_datetime (current_timestamp, 'y_M_d')
;

+---------------------+------------+-----------+
|        _col0        |   _col1    |   _col2   |
+---------------------+------------+-----------+
| 2017-05-19 14:46:12 | 2017_05_19 | 2017_5_19 |
+---------------------+------------+-----------+

https://prestodb.io/docs/current/functions/datetime.html

like image 172
David דודו Markovitz Avatar answered Oct 26 '22 22:10

David דודו Markovitz