begin; do $$ declare tables_to_clear text; begin select string_agg(format('%I.%I', 'public', table_name), ', ' order by table_name) into tables_to_clear from unnest(array[ 'submission_instructor_feedback', 'challenge_retry_requests', 'submission_score_reviews', 'public_challenge_submissions', 'round_quota_operations', 'round_student_quotas', 'challenge_attempts', 'submissions', 'challenge_rounds', 'course_memberships', 'course_access_requests', 'personal_challenge_generations', 'challenge_generation_events', 'challenge_generation_runs', 'challenge_generation_failures', 'challenge_generation_prompt_rules' ]) as listed(table_name) where to_regclass(format('%I.%I', 'public', table_name)) is not null; if tables_to_clear is not null then execute 'truncate table ' || tables_to_clear; end if; end; $$; commit;