title: PostgreSQL CREATE TEMPORARY TABLE inside a plpgsql function
body: <p>I am trying to create a function that does this: </p>
  
  <pre><code>drop table t_rv_openitem;
  select * into t_rv_openitem from rv_openitem;
  select * from t_rv_openitem;
  </code></pre>
  
  <p>I am confused sometimes when it comes to functions in PostgreSQL and get this error:</p>
  
  <blockquote>
    <p>An error has occurred:</p>
    
    <p>ERROR:  syntax error at or near "DROP" LINE 3: DROP TABLE
    t_rv_openitem;</p>
  </blockquote>
  
  <p>I know this seems like a simple task but I am pulling my hair out trying to figure this out.</p>
  
  <p>Here is the full function create statement:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION adempiere.update_t_rv_openitem()
    RETURNS rv_openitem AS
  $BODY$
  
  Drop table t_rv_openitem;
  select * into t_rv_openitem from rv_openitem;
  select * From t_rv_openitem;
  
  $BODY$
    LANGUAGE plpgsql VOLATILE
    COST 100;
  ALTER FUNCTION adempiere.update_t_rv_openitem() OWNER TO adempiere; 
  </code></pre>