Thursday, March 23, 2017

Postgres - Generate Series of dates

Below SQL generate rows of first day of months between 2010 and 2012

select (yr || ''-'' || mnt || ''-'' || 1) ::date as dt from(
(SELECT t.z  AS yr FROM generate_series(2010,2015,1) AS t(z)) z
cross join
(SELECT u.y  AS mnt FROM generate_series(1,12,1) AS u(y)) y
)p

No comments:

Post a Comment