maya
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
omni_rw_insert_geofence_history(integer, integer[], timestamp without time zone)
Parameters
Name
Type
Mode
idunit_in
integer
IN
current_geofences
ARRAY
IN
seendate
timestamp without time zone
IN
Definition
DECLARE gh geofence_history%rowtype; old_geofences integer[]; BEGIN gh.idunit := idunit_in; SELECT array_agg(idgeoreference) INTO old_geofences FROM current_geofence WHERE idunit = idunit_in ORDER by 1; select array_agg(q.gi), array_agg(g.idgeocategory) INTO gh.geofencein,gh.geofencein_category FROM (select unnest(current_geofences) as gi except select unnest(old_geofences)) as q JOIN georeference g ON g.idgeoreference = q.gi; select array_agg(q.go), array_agg(g.idgeocategory) INTO gh.geofenceout,gh.geofenceout_category FROM (select unnest(old_geofences) as go except select unnest(current_geofences)) as q JOIN georeference g ON g.idgeoreference = q.go; gh.seendate := seendate; IF gh.geofencein IS NOT NULL OR gh.geofenceout IS NOT NULL THEN gh.id := nextval('seq_geofencehistory'); INSERT INTO geofence_history SELECT gh.*; RETURN gh.id; END IF; RETURN 0; END;