maya
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
ot_event_part_createchildren_by_iddevice(character varying)
Parameters
Name
Type
Mode
parent_name
character varying
IN
Definition
DECLARE partition_size INTEGER; lower_bound INTEGER; upper_bound INTEGER; lower_bound_aux INTEGER; upper_bound_aux INTEGER; idx INTEGER; idx_exclude INTEGER[]; child_name varchar; BEGIN /* Each partition will include partition_size devices */ partition_size := 500; lower_bound := 1; idx := 1; /* This is because there is a gap in the sec_device sequence */ idx_exclude := '{31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54}'; SELECT max(iddevice) INTO upper_bound FROM device; /* Generate the name for each table */ WHILE idx * partition_size < upper_bound + partition_size LOOP IF idx NOT IN (SELECT unnest(idx_exclude)) THEN lower_bound_aux := (idx -1)*partition_size; upper_bound_aux := idx*partition_size -1; child_name := parent_name || '_'|| lpad(lower_bound_aux::varchar,6,'0') ||'_'|| lpad(upper_bound_aux::varchar,6,'0') ; EXECUTE format('CREATE TABLE %I (LIKE %I INCLUDING ALL, CONSTRAINT check_iddevice_range CHECK(iddevice >= %s and iddevice <= %s)) INHERITS (%I) ;',child_name,parent_name,lower_bound_aux,upper_bound_aux,parent_name); END IF; idx := idx + 1; END LOOP; RETURN true; END