maya
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
tg_insert_event()
Parameters
Name
Type
Mode
Definition
DECLARE partition_number integer; destination_table varchar; command_str varchar; err_msg varchar; BEGIN partition_number := (NEW.iddevice / 500 + 1)::int; destination_table := 'event_part.event_p' || lpad(partition_number::varchar,3,'0'); command_str := 'INSERT INTO '|| destination_table||'(idevent,iddevice,idmessage,latitude,longitude,senddate,receivedate,speed,direction,odometer,ignition_on,panicbutton,speedaverage,securitystatus,enabled,reason,otros,location,gnx_idmessage,otros_char,creationdate) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21)'; EXECUTE command_str USING coalesce(NEW.idevent,nextval('sec_event')),NEW.iddevice,coalesce(NEW.idmessage,null),coalesce(NEW.latitude,null),coalesce(NEW.longitude,null),coalesce(NEW.senddate,timeofday()::timestamptz),coalesce(NEW.receivedate,timeofday()::timestamptz), coalesce(NEW.speed,null), coalesce(NEW.direction,null), coalesce(NEW.odometer,null),coalesce(NEW.ignition_on,null), coalesce(NEW.panicbutton,null), coalesce(NEW.speedaverage,null),coalesce(NEW.securitystatus,null),coalesce(NEW.enabled,true),coalesce(NEW.reason,null),coalesce(NEW.otros,null),coalesce(NEW.location,null),coalesce(NEW.gnx_idmessage,null),coalesce(NEW.otros_char,null),coalesce(NEW.creationdate,timeofday()::timestamptz); RETURN NULL; EXCEPTION WHEN OTHERS THEN GET STACKED DIAGNOSTICS err_msg = MESSAGE_TEXT; RAISE WARNING '%', err_msg; RETURN NEW; END;