2

I am trying to generate a series of DATE objects for each day since January 1st, 2014.

The following query works:

SELECT day::DATE FROM
  (SELECT
     generate_series('2014-01-01'::DATE, now(), '1 day') as day) sq;
    day
------------
 2014-01-01
 2014-01-02
 2014-01-03
 2014-01-04
 2014-01-05
 2014-01-06
 2014-01-07
 2014-01-08
 2014-01-09
 2014-01-10
 2014-01-11
 2014-01-12
 ...
 2015-12-13
 2015-12-14
 2015-12-15
(714 rows)

However, the subquery seems inelegant to me. Is there a way to create the date objects directly from the generate_series query?

1 Answer 1

1
select day::date
from generate_series('2014-01-01'::date, now(), '1 day') sq (day)

Or directly in the select list:

select generate_series('2014-01-01'::date, now(), '1 day')::date as day
Sign up to request clarification or add additional context in comments.

1 Comment

Spot on, amigo. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.