Start to run this simple test as superuser:
Create table cmd_result (str text);
Create Or Replace Function run_all_procedures() Returns void As $$
Begin
copy cmd_result from program 'psql postgres -c "select * from pg_stat_activity;" ';
End;
$$ language plpgsql;
select run_all_procedures();
select * from cmd_result;
Maybe you will need to specify full path to get results from psql...
Now the function...
You must guarantee that postgres unix/windows-user have permission to read do_something.sql then just do:
create table cmd_result (str text);
Create Or Replace Function run_all_procedures() Returns void As $$
Begin
copy cmd_result from program 'psql -f /fullpath/do_something.sql" ';
copy cmd_result from program 'psql -f /fullpath/do_something_else.sql" ';
copy cmd_result from program 'psql -f /fullpath/do_a_final_thing.sql " ';
End;
$$ language plpgsql;
And before calling the function create the temporary table results...
select run_all_procedures();
select * from cmd_result;
Please use fullpath (starting with /) instead of mydir, because postgresql will run the commands in the database directory. If u are in doubt about what i mean try:
create table cmd_result(str text);
copy cmd_result from program '/bin/ls';
select * from cmd_result;
That's all. ** Please select as the correct answer if solves your problem.