I\'d like to get the list of days between the two dates (including them) in a PostgreSQL database. For example, if I had:
If the date range should come from a table expression, you could use the following construct:
DROP TABLE tbl ;
CREATE TABLE tbl (zdate date NOT NULL );
INSERT INTO tbl(zdate) VALUES( '2012-07-01') , ('2012-07-09' );
WITH mima AS (
SELECT MIN(zdate)::timestamp as mi
, MAX(zdate)::timestamp as ma
FROM tbl
)
SELECT generate_series( mima.mi, mima.ma, '1 day':: interval):: date
FROM mima
;
The casts are needed because generate_series() does not take date arguments.