maya
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
ot_rw_insert_geofence_history(integer, integer[], timestamp with time zone)
Parameters
Name
Type
Mode
idunit_in
integer
IN
current_geofences
ARRAY
IN
seendate
timestamp with time zone
IN
Definition
/* v20150513 */ DECLARE gh geofence_history%rowtype; old_geofences integer[]; BEGIN gh.idunit := idunit_in; SELECT odometer INTO gh.odometer FROM device WHERE 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(q.gi) INTO gh.geofencein,gh.geofencein_category FROM (select unnest(current_geofences) as gi except select unnest(old_geofences)) as q; select array_agg(q.go), array_agg(q.go) INTO gh.geofenceout,gh.geofenceout_category FROM (select unnest(old_geofences) as go except select unnest(current_geofences)) as q; SELECT current_geofences INTO gh.current_geofences; 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; END IF; RETURN null; END;