title: PostgreSQL 9.3: Return strings from function
body: <p>I have the following function called as <code>pro()</code>. From which I want to return the strings by union all of two <code>select</code> statements and product output.</p>
  <p><strong>Function</strong>: pro()</p>
  <h1>My try:</h1>
  <pre><code>create or replace function pro()
  returns varchar as
  
  $$
  
  declare
      sql varchar;
      q varchar;
  begin
      sql := 'SELECT DISTINCT  CAST(COUNT(ProductNumber) as varchar) ||'' - Count of the product Number '' as Descp
          FROM product
          UNION ALL
          SELECT DISTINCT CAST(COUNT(ProductName) AS varchar) || '' - Count of the product Name '' as Descp
          FROM product';
  
      raise info '%',sql;
  
      execute sql into q;
  
      return q;
  
  end;
  $$
  
  language plpgsql;
  </code></pre>
  <p><strong>Calling Function</strong>:</p>
  <pre><code>select pro();
  </code></pre>
  <p>This returning only the first part of select statement:</p>
  <pre><code> ______________________________________
  |pro                                   |
  |character varying                     |
  |______________________________________|
  |6 - Count of the product Number       |
  |______________________________________|
  </code></pre>
  <p>But the <strong>expected</strong> result should be:</p>
  <pre><code> ______________________________________
  |pro                                   |
  |character varying                     |
  |______________________________________|
  |6 - Count of the product Number       |
  |______________________________________|
  |6 - Count of the product Name         |
  |______________________________________|
  </code></pre>