tarjontapulssi
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
get_fixed_history()
Parameters
Name
Type
Mode
IN
Definition
DECLARE r toteutus_amounts_history%rowtype; ret_val toteutus_amounts_history%rowtype; curr_val toteutus_amounts_history%rowtype := null; end_time timestamptz; transaction_id bigint; BEGIN FOR r IN SELECT * FROM toteutus_amounts_history order by tyyppi_path, tila, lower(system_time) LOOP IF curr_val is null THEN curr_val = r; END IF; IF (r.tyyppi_path != curr_val.tyyppi_path OR r.tila != curr_val.tila OR r.amount != curr_val.amount OR r.jotpa_amount is distinct from curr_val.jotpa_amount OR r.taydennyskoulutus_amount != curr_val.taydennyskoulutus_amount OR r.tyovoimakoulutus_amount != curr_val.tyovoimakoulutus_amount) THEN ret_val = curr_val; ret_val.system_time = tstzrange(lower(curr_val.system_time), end_time); ret_val.transaction_id = transaction_id; curr_val = r; end_time = upper(r.system_time); transaction_id = r.transaction_id; RETURN NEXT ret_val; ELSE end_time = upper(r.system_time); transaction_id = r.transaction_id; END IF; END LOOP; ret_val = curr_val; ret_val.system_time = tstzrange(lower(curr_val.system_time), end_time); ret_val.transaction_id = transaction_id; RETURN NEXT ret_val; RETURN; END;