title: I can't use variables in psycopg2
body: <p>I need insert values in may DB...
  if i try this way it works:</p>
  <pre><code>INSERT INTO mqtt_recvd_log(recvd_cmd_id,mqtt_topic,mqtt_payload)VALUES(1,'d/status/3C61050259A4','A4 21 07 40 F5 20 85 F4 08 00 00 00 08 00 08 00 08 00 05 09 16 12 1C ');
  </code></pre>
  <p>But I want to insert by variable. So I tried several ways and none was successful:</p>
  <pre><code>topic = 'd/status/3C61050259A4'
  payload= 'A4 21 07 40 F5 20 85 F4 08 00 00 00 08 00 08 00 08 00 05 09 16 12 1C'
  
  conn = psycopg2.connect(&quot;dbname='test' user='postgres' password='admin' host='localhost'&quot;)
  cur = conn.cursor()
  cur.execute(&quot;&quot;&quot;
              INSERT INTO mqtt_recvd_log (recvd_cmd_id,mqtt_topic,mqtt_payload)
              VALUES (1, %s, %s)
              &quot;&quot;&quot;, (topic, payload))
  records = cur.fetchall()
  print(records)
  </code></pre>
  <p>and:</p>
  <pre><code>sql_command = &quot;INSERT INTO mqtt_recvd_log(recvd_cmd_id,mqtt_topic,mqtt_payload)VALUES(1,'%s','%s');&quot;
          
  conn = psycopg2.connect(&quot;dbname='test' user='postgres' password='admin' host='localhost'&quot;)
          
  cur = conn.cursor()
          
  cur.execute(sql_command, topic, payload)
          
  records = cur.fetchall()
  print(records)
  </code></pre>
  <p>and</p>
  <pre><code>cur.execute(f&quot;INSERT INTO mqtt_recvd_log(recvd_cmd_id,mqtt_topic,mqtt_payload)VALUES(1,'{topic}','{payload}');&quot;)
  </code></pre>
  <p>in all cases returns the error:</p>
  <pre><code>records = cur.fetchall()
  psycopg2.ProgrammingError: no results to fetch
  </code></pre>
  <p>I've looked here and elsewhere on how to fix this error but haven't been successful. can anybody help me?</p>