title: table name as variable in postgresql
body: <p>I have a function as follows:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION func(a integer)
    RETURNS integer AS
  $BODY$
  begin
  
       for row in
                       Select id  from table_a    where quantity=1
      loop
          do something
      end loop
  
  end;
  $BODY$
    LANGUAGE plpgsql VOLATILE
  </code></pre>
  
  <p>I need to change this function to take another parameter which tells if to use <code>table_a</code> or <code>table_b</code>. </p>
  
  <p>when <code>whichtouse=1</code> I need to use <code>table_a</code>.</p>
  
  <p>when <code>whichtouse=2</code> I need to use <code>table_b</code>.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION func(a integer,whichtouse integer)
    RETURNS integer AS
  $BODY$
  begin
  
       for row in
                       Select id  from ??? where quantity=1
      loop
          do something
      end loop
  
  end;
  $BODY$
    LANGUAGE plpgsql VOLATILE
  </code></pre>
  
  <p>How can I determin which table to use? </p>