title: plpgsql how to just execute query in a function or procedure
body: <p>I am beginning to learn stored procedures and functions in sql in a postgres database.
  I need an example to get me going for what I am trying to accomplish.</p>
  
  <p>I need to run a procedure and have it return results. For example something like this:</p>
  
  <pre><code>run_query(name):
   begin
   return select * from employees where first_name = $name
   end
  end
  </code></pre>
  
  <p>I want something like the above to return the result set when I run it. Is this possible? thank you for your help in advance!
  Here is the function im trying to create:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION test() RETURNS TABLE(id INT, subdomain varchar, launched_on_xxx timestamp, UVs bigint, PVs bigint) AS
    'SELECT dblink_connect(''other_DB'');
    SELECT    c.id as id, c.subdomain, c.launched_on_xxx, COALESCE(SUM(tbd.new_unique_visitors), 0) AS UVs, COALESCE(SUM(tbd.page_views), 0) AS PVs
      FROM    dblink(''SELECT id, subdomain, launched_on_xxx FROM communities'')
              AS c(id int, subdomain character varying, launched_on_xxx timestamp)
          LEFT OUTER JOIN days_of_center tbd
              ON  c.id = tbd.community_id
      WHERE   c.launched_on_xxx &lt; now()
      GROUP BY    c.id, c.subdomain, c.launched_on_xxx;
      SELECT dblink_disconnect();'
        LANGUAGE SQL;
  </code></pre>