I would like to get the time difference between 'time_type = Lap' AND 'time_type = Start' in order to fill 'time_elapse'. Im almost sure that this code works...
* CREATE OR REPLACE FUNCTION timediff() RETURNS trigger AS $BODY$ DECLARE t_ix real;
BEGIN IF NEW.time_type = 'Lap' THEN SELECT t.time FROM table_ebscb_spa_log04 t WHERE t.fn_name = NEW.fn_name AND t.time_type = 'Start' ORDER BY t.stmtserial DESC LIMIT 1 INTO t_ix; IF NOT FOUND THEN RAISE EXCEPTION USING MESSAGE = 'There is not any previous row...'; ELSE NEW.time_elapse := t_ix - NEW.time; END IF; END IF; return NEW; END $BODY$ LANGUAGE plpgsql VOLATILE*
But I don't know how to get the time difference between the two timestamps cells in a special format: (years/months/days hours:minutes:seconds:miliseconds) like this...