I want to be able to log how long it takes a script with lots of SQL commands to run. I have looked at EXPLAIN, but that is limited to a single command, and do not want to use PL/PGSQL since it does not seem to give me the functionality I need for this. And I will not be running these scripts in the psql client so the \set command will not work for me either.
This psuedo-code block should give you an idea of what I am trying to do:
-- beginning of script
SET begin_time = NOW();
... execute a bunch of SQL commands
-- end of script
SET end_time = NOW();
INSERT INTO execute_log (script_run_time)
SELECT (end_time - start_time);
Is there any easy way to do this in PostgreSQL using just SQL? If not, how can I get the same results?