The easiest trick:
create or replace function get_explain(in qry text, out r text) returns setof text as $$
begin
for r in execute qry loop
raise info '%', r;
return next;
end loop;
return;
end; $$ language plpgsql;
Note that if you don’t really want to modify the data, you shpuld to wrap it in a transaction:
begin;
copy (select get_explain('explain (analyze) select 1;')) to '/tmp/foo.foo';
select get_explain('explain (analyze, format xml) select 1;');
rollback;
A similar function, ready to use, probably already exists, but I did not find it.
PS: it will solve the syntax error problem, but I'm not sure if it solves the timeout problem, because, as mentioned in the documentation:
It is important . Keep in mind that the statement is actually executed when the ANALYZE option is used. Link.
source
share