From 6cffd2662c4647e901342d72f371602c1fdef198 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Wed, 22 May 2013 21:11:39 -0400 Subject: [PATCH] You know what? We don't need tables for the past! --- tables/team_game_stats.tab | 65 +--------------------------- triggers/team_game_stats_ins_trg.sql | 34 +++------------ 2 files changed, 9 insertions(+), 90 deletions(-) diff --git a/tables/team_game_stats.tab b/tables/team_game_stats.tab index a8e0275..4ed77f5 100755 --- a/tables/team_game_stats.tab +++ b/tables/team_game_stats.tab @@ -20,70 +20,8 @@ WITH ( CREATE INDEX team_game_stats_ix01 on team_game_stats(game_id); ALTER TABLE xonstat.team_game_stats OWNER TO xonstat; -CREATE TABLE xonstat.team_game_stats_2011Q2 ( - CHECK ( create_dt >= DATE '2011-04-01' AND create_dt < DATE '2011-07-01' ) -) INHERITS (team_game_stats); - -CREATE INDEX team_game_stats_2011Q2_ix01 on team_game_stats_2011Q2(game_id); -ALTER TABLE xonstat.team_game_stats_2011Q2 OWNER TO xonstat; - - -CREATE TABLE xonstat.team_game_stats_2011Q3 ( - CHECK ( create_dt >= DATE '2011-07-01' AND create_dt < DATE '2011-10-01' ) -) INHERITS (team_game_stats); - -CREATE INDEX team_game_stats_2011Q3_ix01 on team_game_stats_2011Q3(game_id); -ALTER TABLE xonstat.team_game_stats_2011Q3 OWNER TO xonstat; - - -CREATE TABLE xonstat.team_game_stats_2011Q4 ( - CHECK ( create_dt >= DATE '2011-10-01' AND create_dt < DATE '2012-01-01' ) -) INHERITS (team_game_stats); - -CREATE INDEX team_game_stats_2011Q4_ix01 on team_game_stats_2011Q4(game_id); -ALTER TABLE xonstat.team_game_stats_2011Q4 OWNER TO xonstat; - - -CREATE TABLE xonstat.team_game_stats_2012Q1 ( - CHECK ( create_dt >= DATE '2012-01-01' AND create_dt < DATE '2012-04-01' ) -) INHERITS (team_game_stats); - -CREATE INDEX team_game_stats_2012Q1_ix01 on team_game_stats_2012Q1(game_id); -ALTER TABLE xonstat.team_game_stats_2012Q1 OWNER TO xonstat; - - -CREATE TABLE xonstat.team_game_stats_2012Q2 ( - CHECK ( create_dt >= DATE '2012-04-01' AND create_dt < DATE '2012-07-01' ) -) INHERITS (team_game_stats); - -CREATE INDEX team_game_stats_2012Q2_ix01 on team_game_stats_2012Q2(game_id); -ALTER TABLE xonstat.team_game_stats_2012Q2 OWNER TO xonstat; - - -CREATE TABLE xonstat.team_game_stats_2012Q3 ( - CHECK ( create_dt >= DATE '2012-07-01' AND create_dt < DATE '2012-10-01' ) -) INHERITS (team_game_stats); - -CREATE INDEX team_game_stats_2012Q3_ix01 on team_game_stats_2012Q3(game_id); -ALTER TABLE xonstat.team_game_stats_2012Q3 OWNER TO xonstat; - - -CREATE TABLE xonstat.team_game_stats_2012Q4 ( - CHECK ( create_dt >= DATE '2012-10-01' AND create_dt < DATE '2013-01-01' ) -) INHERITS (team_game_stats); - -CREATE INDEX team_game_stats_2012Q4_ix01 on team_game_stats_2012Q4(game_id); -ALTER TABLE xonstat.team_game_stats_2012Q4 OWNER TO xonstat; - - -CREATE TABLE xonstat.team_game_stats_2013Q1 ( - CHECK ( create_dt >= DATE '2013-01-01' AND create_dt < DATE '2013-04-01' ) -) INHERITS (team_game_stats); - -CREATE INDEX team_game_stats_2013Q1_ix01 on team_game_stats_2013Q1(game_id); -ALTER TABLE xonstat.team_game_stats_2013Q1 OWNER TO xonstat; - +-- 2013 CREATE TABLE xonstat.team_game_stats_2013Q2 ( CHECK ( create_dt >= DATE '2013-04-01' AND create_dt < DATE '2013-07-01' ) ) INHERITS (team_game_stats); @@ -108,6 +46,7 @@ CREATE INDEX team_game_stats_2013Q4_ix01 on team_game_stats_2013Q4(game_id); ALTER TABLE xonstat.team_game_stats_2013Q4 OWNER TO xonstat; +-- 2014 CREATE TABLE xonstat.team_game_stats_2014Q1 ( CHECK ( create_dt >= DATE '2014-01-01' AND create_dt < DATE '2014-04-01' ) ) INHERITS (team_game_stats); diff --git a/triggers/team_game_stats_ins_trg.sql b/triggers/team_game_stats_ins_trg.sql index b88ace9..a4b79e6 100644 --- a/triggers/team_game_stats_ins_trg.sql +++ b/triggers/team_game_stats_ins_trg.sql @@ -1,43 +1,23 @@ CREATE OR REPLACE FUNCTION team_game_stats_ins() RETURNS TRIGGER AS $$ BEGIN - -- 2011 - IF (NEW.create_dt >= DATE '2011-04-01' AND NEW.create_dt < DATE '2011-07-01') THEN - INSERT INTO team_game_stats_2011Q2 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2011-07-01' AND NEW.create_dt < DATE '2011-10-01') THEN - INSERT INTO team_game_stats_2011Q3 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2011-10-01' AND NEW.create_dt < DATE '2012-01-01') THEN - INSERT INTO team_game_stats_2011Q4 VALUES (NEW.*); - - -- 2012 - ELSIF (NEW.create_dt >= DATE '2012-01-01' AND NEW.create_dt < DATE '2012-04-01') THEN - INSERT INTO team_game_stats_2012Q1 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2012-04-01' AND NEW.create_dt < DATE '2012-07-01') THEN - INSERT INTO team_game_stats_2012Q2 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2012-07-01' AND NEW.create_dt < DATE '2012-10-01') THEN - INSERT INTO team_game_stats_2012Q3 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2012-10-01' AND NEW.create_dt < DATE '2013-01-01') THEN - INSERT INTO team_game_stats_2012Q4 VALUES (NEW.*); - -- 2013 - ELSIF (NEW.create_dt >= DATE '2013-01-01' AND NEW.create_dt < DATE '2013-04-01') THEN - INSERT INTO team_game_stats_2013Q1 VALUES (NEW.*); - ELSIF (NEW.create_dt >= DATE '2013-04-01' AND NEW.create_dt < DATE '2013-07-01') THEN + IF (NEW.create_dt >= DATE '2013-04-01' AND NEW.create_dt < DATE '2013-07-01') THEN INSERT INTO team_game_stats_2013Q2 VALUES (NEW.*); ELSIF (NEW.create_dt >= DATE '2013-07-01' AND NEW.create_dt < DATE '2013-10-01') THEN - INSERT INTO team_game_stats_2013Q2 VALUES (NEW.*); + INSERT INTO team_game_stats_2013Q3 VALUES (NEW.*); ELSIF (NEW.create_dt >= DATE '2013-10-01' AND NEW.create_dt < DATE '2013-01-01') THEN - INSERT INTO team_game_stats_2013Q2 VALUES (NEW.*); + INSERT INTO team_game_stats_2013Q4 VALUES (NEW.*); -- 2014 ELSIF (NEW.create_dt >= DATE '2014-01-01' AND NEW.create_dt < DATE '2014-04-01') THEN - INSERT INTO team_game_stats_2013Q2 VALUES (NEW.*); + INSERT INTO team_game_stats_2014Q1 VALUES (NEW.*); ELSIF (NEW.create_dt >= DATE '2014-04-01' AND NEW.create_dt < DATE '2014-07-01') THEN - INSERT INTO team_game_stats_2013Q2 VALUES (NEW.*); + INSERT INTO team_game_stats_2014Q2 VALUES (NEW.*); ELSIF (NEW.create_dt >= DATE '2014-07-01' AND NEW.create_dt < DATE '2014-10-01') THEN - INSERT INTO team_game_stats_2013Q2 VALUES (NEW.*); + INSERT INTO team_game_stats_2014Q3 VALUES (NEW.*); ELSIF (NEW.create_dt >= DATE '2014-10-01' AND NEW.create_dt < DATE '2015-10-01') THEN - INSERT INTO team_game_stats_2013Q2 VALUES (NEW.*); + INSERT INTO team_game_stats_2014Q4 VALUES (NEW.*); ELSE RAISE EXCEPTION 'Date out of range. Fix the team_game_stats_ins() trigger!'; -- 2.39.2