Untitled
unknown
plain_text
10 months ago
1.5 kB
5
Indexable
DO $$ DECLARE batch_size INT := 1000; pointer INT := 0; BEGIN LOOP WITH cte AS ( SELECT ao.function_id, ao.user_id, ao.status, ao.time_start, ao.time_end, ao.request_line, ao.request_body, ao.response_body, ao.client_host, ao.db_connection_info, func.function_category, row_number() OVER () AS rn FROM auditing_old ao INNER JOIN auditing_function func ON ao.function_id = func.function_id WHERE func.function_category = 1 or (func.function_category = 2 and ao.time_start >= now() - interval '31 day') OFFSET pointer LIMIT batch_size ) INSERT INTO auditing (FUNCTION_ID, USER_ID, STATUS, TIME_START, TIME_END, REQUEST_LINE, REQUEST_BODY, RESPONSE_BODY, CLIENT_HOST, DB_CONNECTION_INFO, function_category) SELECT function_id, user_id, status, time_start, time_end, request_line, request_body, response_body, client_host, db_connection_info, function_category FROM cte; IF NOT FOUND THEN EXIT; END IF; pointer := pointer + batch_size; END LOOP; END $$;
Editor is loading...
Leave a Comment