create extension pg_show_plans;
show pg_show_plans.is_enabled;
 pg_show_plans.is_enabled 
--------------------------
 on
(1 row)

show pg_show_plans.max_plan_length;
 pg_show_plans.max_plan_length 
-------------------------------
 16384
(1 row)

create function nest()
  returns table (level int, plan text)
  language plpgsql
as $$
  begin
    return query
      select pg_show_plans.level, pg_show_plans.plan from pg_show_plans
        where pg_show_plans.level >= 0;
  end;
$$;
-- text output
set pg_show_plans.plan_format = 'text';
ERROR:  parameter "pg_show_plans.plan_format" cannot be changed without restarting the server
show pg_show_plans.plan_format;
 pg_show_plans.plan_format 
---------------------------
 text
(1 row)

select level, plan from pg_show_plans;
 level |                                 plan                                  
-------+-----------------------------------------------------------------------
     0 | Function Scan on pg_show_plans  (cost=0.00..10.00 rows=1000 width=36)
(1 row)

select * from nest();
 level |                                 plan                                 
-------+----------------------------------------------------------------------
     0 | Function Scan on nest  (cost=0.25..10.25 rows=1000 width=36)
     1 | Function Scan on pg_show_plans  (cost=0.00..12.50 rows=333 width=36)+
       |   Filter: (level >= 0)
(2 rows)

