title: PL/pgSQL functions: How to return a normal table with multiple columns using an execute statement
body: <p>I've got this <strong>PL/pgSQL</strong> function which must return some users information.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION my_function(
          user_id integer
      ) RETURNS TABLE(
              id integer, 
              firstname character varying,
              lastname  character varying
          ) AS $$
      DECLARE
          ids character varying;
      BEGIN
          ids := '';
          --Some code which build the ids string, not interesting for this issue
          RETURN QUERY 
              EXECUTE 'SELECT 
                          users.id, 
                          users.firstname, 
                          users.lastname
                      FROM public.users 
                      WHERE ids IN (' || ids || ')';
      END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>The problem I'm facing is that the result of the function is a single columns table like this:</p>
  
  <pre><code>╔═══╦═════════════════════╗
  ║   ║my_function          ║
  ╠═══╬═════════════════════╣
  ║ 1 ║ (106,Ned,STARK)     ║
  ║ 2 ║ (130,Rob,STARK)     ║
  ╚═══╩═════════════════════╝
  </code></pre>
  
  <p>While I expected:</p>
  
  <pre><code>╔═══╦════════════╦════════════╦═════════════╗
  ║   ║ id         ║ firstname  ║ lastname    ║
  ╠═══╬════════════╬════════════╬═════════════╣
  ║ 1 ║ 106        ║ Ned        ║ STARK       ║
  ║ 2 ║ 103        ║ Rob        ║ STARK       ║
  ╚═══╩════════════╩════════════╩═════════════╝
  </code></pre>
  
  <p>I think (but not sure) the problem comes from the <code>EXECUTE</code> statement, but I can't see how to do otherwise.</p>
  
  <p>Any ideas?</p>