title: How to pass parameterized statements with values and table names to Psycopg2?
body: <p>I'm basically trying to accomplish what the answerer pointed out here: <a href="https://stackoverflow.com/questions/9354392/psycopg2-cursor-execute-with-sql-query-parameter-causes-syntax-error">psycopg2 cursor.execute() with SQL query parameter causes syntax error</a></p>
  
  <p>My statement is:</p>
  
  <pre><code>    cursor.execute('SELECT %s FROM %s WHERE %s = %s' % (pkey,table,field, "%s"), (value))
  </code></pre>
  
  <p>But when I run it I get the error:</p>
  
  <pre><code>---&gt; 89         cur.execute('SELECT %s FROM %s WHERE %s = %s' % (pkey,table,field, "%s"), (value))
       90         res=cur.fetchone()
       91         if res==None:
  
  TypeError: not all arguments converted during string formatting
  </code></pre>