title: PSQL how to have a recursive query with a variable parameter
body: <p>I need a query in SQL/PSQL that gives me a hierarchical relation of a specifiable parent.</p>
  
  <p>I tried just a recursive query but I can't specify the first parent, then I tried putting the whole CTE expression in a function and finally I tried using a declared variable and redeclare it anytime I use the query.</p>
  
  <pre><code>DECLARE @procura = null;
  
  WITH RECURSIVE hierarquia (procura) AS (
      SELECT categoria, super_categoria
      FROM
      CONSTITUIDA
      WHERE
      super_categoria = @procura
      UNION
      SELECT c.categoria, c.super_categoria
      FROM
      CONSTITUIDA c
      INNER JOIN hierarquia h ON h.categoria = c.super_categoria
  ) SELECT
  *
  FROM hierarquia;
  </code></pre>
  
  <p>Note:
  CONSTITUIDA has 2 columns, categoria and super_categoria which are, respectively, the child and parent.</p>
  
  <p>I want to specify a parent of CONSTITUIDA and it should return all children of that parent, at all recursion depths.</p>