I have a batch of SQL benchmark queries that I would like to execute and compute their timing. I do not want to obtain the execution plan with the command EXECUTE ANALYZE.
Based on the approach suggested here Get execution time of PostgreSQL query I have written a procedure that contains for each query the following code
-------------------------
Query = 'Q1';
StartTime := clock_timestamp();
PERFORM <** Query 1 goes here **>
EndTime := clock_timestamp();
Duration := 1000 * ( extract(epoch from EndTime) - extract(epoch from StartTime) );
INSERT INTO execution_tests VALUES (Query, StartTime, EndTime, Duration);
-------------------------
I use PERFORM instead of SELECT to execute the query and discard the result.
That works for simple queries, but I have many queries that have a WITH clause. According to the manual
For WITH queries, use PERFORM and then place the query in parentheses. (In this case, the query can only return one row.)
However, all the WITH queries I need to benchmark return multiple rows.
How to solve this problem ?