maya
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
ot_rw_createchildpart_alert(date)
Parameters
Name
Type
Mode
in_target_date
date
IN
Definition
/* v20150416 RRB */ DECLARE table_name varchar; start_week timestamptz; end_week timestamptz; BEGIN SET time zone 'UTC'; SET search_path TO public; table_name := (select 'alert_p'|| to_char(in_target_date,'IYYY')||'w'||to_char(in_target_date,'IW') as iso_year_week); start_week := (select date_trunc('week',in_target_date)); end_week := start_week + '7 days'::interval; EXECUTE 'CREATE TABLE '||table_name ||' (LIKE alert INCLUDING DEFAULTS INCLUDING INDEXES INCLUDING COMMENTS) INHERITS (public.alert)'; EXECUTE 'ALTER TABLE '||table_name||' ADD CONSTRAINT ck_'||table_name||'_part_creationdate_range CHECK(creationdate >= '|| quote_literal(start_week) ||' AND creationdate < '|| quote_literal(end_week)||')'; RAISE NOTICE 'Created table %', table_name; RETURN true; EXCEPTION WHEN OTHERS THEN RAISE WARNING '%,%', SQLSTATE, SQLERRM; RETURN false; END;