title: Depth of a PostgreSQL function
body: <p>How can i know the depth of a stored procedure (they are called function in postgresql), that function calls two other recursive function ?
  Is it possible to know many time that function was called.
  The reason why i want to do that is because i would like to switch to an iterative approach rather than a recursive which is more efficient in my understanding.</p>
  
  <p>The first function is below:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.generategrid(parameters)
   RETURNS SETOF text AS
  $BODY$
  
  DECLARE
        /* input params */
  
  BEGIN
        execute generaterowandcols(parameters)
  END;
  
  $BODY$
  </code></pre>
  
  <p>And as a mentioned above it calls another function</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.generaterowandcols(parameters)
  $BODY$
  
  DECLARE
        /* input params */
  
  BEGIN
        execute generaterow(parameters)
  
        execute generaterowandcols(parameters)
  END;
  
  $BODY$
  </code></pre>
  
  <p>And the function that is before calls the fucntion below</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.generaterow(parameters)
  $BODY$
  
  DECLARE
        /* input params */
  
  BEGIN
        execute generaterow(parameters)
  
  END;
  
  $BODY$
  </code></pre>