This is a workaround. DECLARE tables CURSOR FOR SELECT * FROM information_schema.tables where table_schema = 'public' ORDER BY "table_name" --presumably 'ASC' LIMIT ((select count(*) from information_schema.tables where table_schema = 'public')-1); --Because the following prepared string starts with a 'UNION ALL', --this completes the query string with a select starting with the last table sql_string text := 'SELECT columns FROM last_table_in_the_list'; BEGIN FOR table_record IN tables LOOP sql_string := sql_string || ' UNION ALL SELECT columns FROM ' || quote_IDENT(table_record."table_name"); END LOOP; sql_string := sql_string||';'; RETURN sql_string; --EXECUTE sql_string; END;