title: How to return table from PL/pgSQL function?
body: <pre><code>CREATE OR REPLACE FUNCTION my_function(user_id integer) 
       RETURNS TABLE(id integer, firstname character varying, lastname character varying) 
  AS $$
  DECLARE
      ids INTEGER[];
  BEGIN
       ids := ARRAY[1,2];
       RETURN QUERY
           SELECT users.id, users.firstname, users.lastname
           FROM public.users
           WHERE users.id = ANY(ids);
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p><br></p>
  
  <pre><code>select * from my_function(1);
  </code></pre>