title: How to write WITH(CTE) within function in PostgreSQL
body: <p>I am trying to use "WITH" that is Common Table Expression within the function of PostgreSQL.  </p>
  
  <p>Here is the following example:</p>
  
  <p><strong>Example</strong>:  </p>
  
  <pre><code> Create or replace function withFunction() returns void as
   $Body$
   Begin
    WITH cmn_l1
    AS
    (
      SELECT "PhoneNumber1","PhoneNumber2",
      DENSE_RANK() OVER(Partition by "PhoneNumber1" Order By "PhoneNumber2" )FoundIn
      From tablename;
    )
   SELECT DISTINCT * INTO temptable
   FROM cmn_l1
   WHERE FoundIn &gt; 1;
  
   end;
   $Body$
   language plpgsql;
  </code></pre>
  
  <p><strong>Question</strong>: How to execute and get values into the above table using WITH within function? </p>