title: Passing table name as a parameter in psycopg2
body: <p>I have the following code, using pscyopg2:</p>
  
  <pre><code>sql = 'select %s from %s where utctime &gt; %s and utctime &lt; %s order by utctime asc;'
  data = (dataItems, voyage, dateRangeLower, dateRangeUpper)
  rows = cur.mogrify(sql, data)
  </code></pre>
  
  <p>This outputs:</p>
  
  <pre><code>select 'waterTemp, airTemp, utctime' from 'ss2012_t02' where utctime &gt; '2012-05-03T17:01:35+00:00'::timestamptz and utctime &lt; '2012-05-01T17:01:35+00:00'::timestamptz order by utctime asc;
  </code></pre>
  
  <p>When I execute this, it falls over - this is understandable, as the quotes around the table name are illegal.</p>
  
  <p>Is there a way to legally pass the table name as a parameter, or do I need to do a (explicitly warned against) string concatenation, ie:</p>
  
  <pre><code>voyage = 'ss2012_t02'
  sql = 'select %s from ' + voyage + ' where utctime &gt; %s and utctime &lt; %s order by utctime asc;'
  </code></pre>
  
  <p>Cheers for any insights.</p>