Skip to content
Advertisement

generate date range between min and max dates Athena presto SQL sequence error

I’m attempting to generate a series of dates in Presto SQL (Athena) using unnest and sequence something similair to generate_series in postgres.

my table looks like


I’m aiming for an output as follows


I’ve attempted to use the following query to achieve this – however I get an error when trying to unnest my date sequence

which yields the following error :

Is this a limitation of Athena’s flavour of Presto SQL or have I made a school boy error somewhere?

Advertisement

Answer

You need to provide interval to generate date sequence (in this case interval '1' day):

Output:

job_name seq
A [2021-08-21 00:00:00.000, 2021-08-22 00:00:00.000, 2021-08-23 00:00:00.000, 2021-08-24 00:00:00.000, 2021-08-25 00:00:00.000]
B [2021-08-07 00:00:00.000, 2021-08-08 00:00:00.000, 2021-08-09 00:00:00.000, 2021-08-10 00:00:00.000, 2021-08-11 00:00:00.000, 2021-08-12 00:00:00.000, 2021-08-13 00:00:00.000, 2021-08-14 00:00:00.000, 2021-08-15 00:00:00.000, 2021-08-16 00:00:00.000, 2021-08-17 00:00:00.000, 2021-08-18 00:00:00.000, 2021-08-19 00:00:00.000, 2021-08-20 00:00:00.000, 2021-08-21 00:00:00.000, 2021-08-22 00:00:00.000, 2021-08-23 00:00:00.000, 2021-08-24 00:00:00.000]
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement