Geek(Wisdom).com - [The place for open source wisdom.]A place to share geekly ideas.Populating a PostgreSQL Calendar Table- October 28, 2007 I'm using PostgreSQL for my data warehouse. I needed a calendar table for doing joins and a quick way to populate it. So I created my calendar table with: CREATE TABLE "CALENDAR" ( "YYYYMMDD" date NOT NULL ); Then I populated it with the following SQL: INSERT INTO "CALENDAR" ("YYYYMMDD") select to_date('20000101', 'YYYYMMDD') + s.a as dates from generate_series(0,36524,1) as s(a); This quickly puts records into the CALENDAR table for every day starting with 112000 and ending with 12312099.http://www.geekwisdom.com/dyn/node/195 |