Postgresql – View the final query executed by PostgreSQL Function

explainperformancepostgresql

I have a PostgreSQL function with Language plpgsql.
Since the EXPLAIN ANALYZE VERBOSE for my function executed like this:

EXPLAIN ANALYZE VERBOSE SELECT foo()

doesn't seem to log any valuable details except the following:

"Result  (cost=0.00..5.25 rows=1000 width=32) (actual time=122.115..122.204 rows=25 loops=1)"
"  Output: postgre.foo()"
"Planning time: 0.026 ms"
"Execution time: 122.243 ms"

I wanted to know if there is any way I can see the real query\queries used by the function, so that I can do EXPLAIN ANALYZE on these SQL queries.

Thanks.

Best Answer

In psql just do \sf name_of_function and it will show you the source code. Or \ef will load it into an editor.