Populating a PostgreSQL Calendar Table
- Blogs:
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:
Then I populated it with the following SQL:
This quickly puts records into the CALENDAR table for every day starting with 1/1/2000 and ending with 12/31/2099.
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 1/1/2000 and ending with 12/31/2099.
- geekwisdom's blog
- Login or register to post comments

