karthik
karthik

Reputation: 499

How to query the time in unix epoch timestamp in aws athena

I have a simple table contains the node, message, starttime, endtime details where starttime and endtime are in unix timestamp. The query I am running is:

select node, message, (select from_unixtime(starttime)), (select from_unixtime(endtime)) from table1 WHERE try(select from_unixtime(starttime)) > to_iso8601(current_timestamp - interval '24' hour) limit 100

The query is not working and throwing the syntax error.

I am trying to fetch the following information from the table:

Upvotes: 5

Views: 13302

Answers (2)

David A
David A

Reputation: 191

to search last week you can use

WHERE your_date >= to_unixtime(CAST(now() - interval '7' day AS timestamp))

Upvotes: 1

Guru Stron
Guru Stron

Reputation: 142093

You don't need "extra" selects and you don't need to_iso8601 in the where clasue:

WITH dataset AS (
    SELECT * FROM (VALUES   
       (1627409073, 1627409074),
       (1627225824, 1627225826)
 ) AS t (starttime, endtime))

SELECT from_unixtime(starttime), from_unixtime(endtime)
FROM
dataset
WHERE from_unixtime(starttime) > (current_timestamp - interval '24' hour) limit 100

Output:

_col0 _col1
2021-07-27 18:04:33.000 2021-07-27 18:04:34.000

Upvotes: 3

Related Questions