From edf90be5cf862cd6ce706fe20d7090892cce3b09 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Mon, 17 Nov 2014 22:16:40 -0500 Subject: [PATCH] Add table definitions. --- scripts/gen_trigger.shl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/gen_trigger.shl b/scripts/gen_trigger.shl index 1746278..3a6d2e8 100755 --- a/scripts/gen_trigger.shl +++ b/scripts/gen_trigger.shl @@ -4,6 +4,31 @@ table=$1 start_year=$2 end_year=$3 +for year in `seq $start_year $end_year` +do + for qtr in "q1" "q2" "q3" "q4" + do + printf "CREATE TABLE IF NOT EXISTS xonstat.%s_%s%s ( \n" $table $year $qtr + if [[ $qtr = "q1" ]] + then + printf "\tCHECK ( create_dt >= DATE '%s-01-01' AND create_dt < DATE '%s-04-01' ) \n" $year $year + elif [[ $qtr = "q2" ]] + then + printf "\tCHECK ( create_dt >= DATE '%s-04-01' AND create_dt < DATE '%s-07-01' ) \n" $year $year + elif [[ $qtr = "q3" ]] + then + printf "\tCHECK ( create_dt >= DATE '%s-07-01' AND create_dt < DATE '%s-10-01' ) \n" $year $year + elif [[ $qtr = "q4" ]] + then + next_year=$[year + 1] + printf "\tCHECK ( create_dt >= DATE '%s-10-01' AND create_dt < DATE '%s-01-01' ) \n" $year $next_year + fi + + printf ") INHERITS (%s);\n\n" $table + done +done +printf "\n" + printf "CREATE OR REPLACE FUNCTION %s_ins()\n" $table printf "RETURNS TRIGGER AS \$\$\n" printf "BEGIN\n" -- 2.39.2