 
 -- NON OBJ TRIGGERS
 CREATE OR REPLACE FUNCTION nonobj_before_change_trigger () RETURNS "trigger" AS $$
-DECLARE
-    tmp text;
 BEGIN
     EXECUTE 'INSERT INTO old_'||TG_RELNAME||' SELECT now(),'''||TG_OP||''',* FROM '||TG_RELNAME||' WHERE id='||quote_literal(OLD.id);
     IF TG_OP='UPDATE' THEN

    RETURN NULL;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION reodb_before_delete_trigger () RETURNS "trigger" AS $$
BEGIN
    IF ref_name(OLD.state_id) IN ('deleted','temporary') THEN

    RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION reodb_simple_change_trigger () RETURNS "trigger" AS $$
BEGIN
    EXECUTE 'INSERT INTO old_'||TG_RELNAME||' SELECT now(),'''||TG_OP||''',* FROM '||TG_RELNAME||' WHERE obj_id='||OLD.obj_id;
    IF TG_OP='UPDATE' THEN
