Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

substr at Amazon Athena

At Amazon Athena, I want to extract only the character string "2017-07-27" from the character string "2017-07-27 12:10:08".

SELECT SUBSTRING (event_datetime.s, 0, 10) FROM production limit 10

I tried it like this which only returns numbers 0 to 10.

At Athena, is it possible to cut character strings? If so, how can I do it?

Or, if you know how to cast "2017-07-27 12:10:08" to date type, that's fine.

Thank you.

like image 667
Akihiro Seki Avatar asked Jul 27 '17 05:07

Akihiro Seki


People also ask

How do you substring in Athena?

You can use SUBSTR to substring a column value. Here is the string function reference page. NOTE that the index position of the first character is 1 (not zero), the same as in standard SQL.

Does Amazon Athena use SQL?

Amazon Athena uses Presto with ANSI SQL support and works with a variety of standard data formats, including CSV, JSON, ORC, Avro, and Parquet. Athena is ideal for interactive querying and can also handle complex analysis, including large joins, window functions, and arrays.

What is the use of Amazon Athena?

Amazon Athena helps you analyze data stored in Amazon S3. You can use Athena to run interactive analytics using ANSI SQL, without the need to aggregate or load the data into Athena. Amazon Athena can process unstructured, semi-structured, and structured data sets.

Who is Amazon Athena?

Amazon Athena is a service that enables data analysts to perform interactive queries in the web-based cloud storage service, Amazon Simple Storage Service (S3). Athena is used with large-scale data sets. Amazon S3 is designed for online backup and archiving of data and applications on Amazon Web Services (AWS).


1 Answers

You can use SUBSTR to substring a column value.

Here is the string function reference page.

In your case, this would lead to the following statement:

SELECT SUBSTR(event_datetime.s, 1, 10) FROM production limit 10

NOTE that the index position of the first character is 1 (not zero), the same as in standard SQL.

like image 146
jens walter Avatar answered Oct 03 '22 03:10

jens walter