Write a function that updates version_actual_period_start with type timestamp. Look for an entry with the condition version_actual_period_end > current_timestamp . the user specifies the desired date, and the previous one, according to the time of the relevance of the record, is updated version_actual_period_end-becomes the same, but 1 second less. Input parameters time, database table name, version_meta_id array. Plpgsql
CREATE OR REPLACE FUNCTION public.update_version_actual_period_start( IN p_time timestamp, IN p_table_name character varying, IN p_version_meta_id integer[]) RETURNS integer AS $BODY$ declare l_count integer; l_version_actual_period_start timestamp; l_version_actual_period_end timestamp; BEGIN l_count = 0; FOR i IN 1..array_length(p_version_meta_id, 1) LOOP SELECT version_actual_period_start, version_actual_period_end INTO l_version_actual_period_start, l_version_actual_period_end FROM $1 WHERE version_meta_id = p_version_meta_id[i]; IF (l_version_actual_period_end > current_timestamp) THEN l_count = l_count + 1; l_version_actual_period_start = p_time;