Trying to run a Postgres explain analyze statement with rollback : I am building a java program that needs to automatically collect data on SQL statements before scheduling them. The program right now runs an explain statement and parses the results.

I need the time parameter, so I need to run as analyze, but I don't want to affect any data, so I need rollback. When I attempt to run this all as a block, as suggested in the PostgreSQL documentation, with:

    BEGIN;
    EXPLAIN ANALYZE VERBOSE ...(statement)
    ROLLBACK;


I don't get the results of the explain statement, rather I get that these block of queries didn't affect any rows.

So I am not sure the best way to get this data. My thought is perhaps build out a function where the statement is a text argument, and the there's a table returned that's just 1 row/column containing the explain output, but I'm not really a PostgreSQL function whiz so a simpler alternative is preferable.

Not really sure how to go about this. Any assistance would be helpful!