title: How to return a result from an anonymous PL/pgSQL block?
body: <p>PostgreSQL version I'm using is 9.3.</p>
  
  <p>I've written a code which contains the following chunk:</p>
  
  <pre><code>String queryString = "do $$\n"
  + "&lt;&lt; outerblock &gt;&gt;\n" 
  + "DECLARE\n"
      + "table_name varchar DEFAULT 'partner.partner_statistic';\n"
  + "BEGIN\n"
  +    "EXECUTE 'SELECT * FROM ' || table_name;\n"
  + "END;\n"
  + "$$ LANGUAGE plpgsql; \n";
  Query query = getSession().createSQLQuery(queryString);
  List l = query.list();
  </code></pre>
  
  <p>In the debugger, I recieve the message:</p>
  
  <blockquote>
    <p>[org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78)]
    : No results were returned by the query.</p>
  </blockquote>
  
  <p>at the line </p>
  
  <pre><code>List l = criteria.list();
  </code></pre>
  
  <p>How can I rewrite the query to return actual result?</p>