Skip to content

Instantly share code, notes, and snippets.

@seanickle
Last active September 4, 2023 00:51
Show Gist options
  • Save seanickle/10e091da41bb6c4218abf1182397ca2d to your computer and use it in GitHub Desktop.
Save seanickle/10e091da41bb6c4218abf1182397ca2d to your computer and use it in GitHub Desktop.
AWS Athena timestamp select query

Doing a SELECT on a specific timestamp range

  • Here, the Athena table athena_table has the columns timestamp, day, month, year, id
select timestamp,month,day,year,id
from athena_table

WHERE month = 8 and day = 15
AND (CAST(timestamp as varchar) BETWEEN '2018-08-15 22:00:00' AND '2018-08-15 22:10:00')
                                                                     
ORDER BY timestamp DESC
x timestamp month day year id
1 2018-08-15 22:03:25.296 15 8 2018 12344
2 2018-08-15 22:02:59.266 15 8 2018 12345

length can also be checked on a varchar field

SELECT * FROM blah WHERE length(blah_field) = 10

can treat a string field as a number as well..

SELECT * FROM blah  WHERE (cast(blah_numeric_string_field as double)) >= 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment