maya
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
ot_rw_maint_alert_recent_add_new()
Parameters
Name
Type
Mode
Definition
DECLARE r record; _oidalertrecent oid; BEGIN SET statement_timeout = '500 ms'; /* To keep only the latest 8 partitions of alert linked alert_recent */ DROP table if exists a; CREATE temporary table a as SELECT 'alert_p'||extract('year' from g)::varchar||'_'||lpad(extract('month' from g)::varchar,2,'0')||'_'||lpad(extract('day' from g)::varchar,2,'0')::varchar as p FROM generate_series(now()::date - '6 days'::interval,now()::date + '2 days'::interval,'1 day'::interval) g; SELECT oid INTO _oidalertrecent FROM pg_class WHERE relname = 'alert_recent'; /* New tables to inherit*/ FOR r IN SELECT p FROM a EXCEPT SELECT c.oid::pg_catalog.regclass::varchar FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhrelid AND i.inhparent = _oidalertrecent LOOP EXECUTE format('ALTER TABLE %I INHERIT alert_recent; ',r.p); END LOOP; RETURN true; EXCEPTION WHEN OTHERS THEN RAISE NOTICE '%,%', SQLSTATE,SQLERRM; RETURN false; END