Use generate_series()
, does exactly what you need:
SELECT generate_series('2013-09-20'::date
, '2013-09-27'::date
, interval '1 day')::date;
Takes two timestamp
variables, but dates
are also accepted.
Returns timestamp with time zone
, so I cast to date
according to your request.
A more verbose, but syntactically clearer version is to use the set returning function (SRF) as FROM
item:
SELECT *
FROM generate_series('2013-09-20'::date
, '2013-09-27'::date
, interval '1 day')::date;
Consider the comments below.