title: How can I write an SQL update command using %s in psycopg2 with python
body: <p>I am new to python, currently learning. So I am using the psycopg2 library to run postgresql query and have an insert command like this:</p>
  <pre class="lang-py prettyprint-override"><code>    cursor.execute(
          &quot;INSERT INTO test_case (run_id, listener_id, tc_name, elapsed_time_in_ms, elapsed_time_in_hr_min_sec, &quot;
          &quot;epoch_time, status, message, tags) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s);&quot;,
          (
              run_id_from_test_run,
              attributes.get(&quot;id&quot;),
              attributes.get(&quot;originalname&quot;),
              attributes.get(&quot;elapsedtime&quot;),
              convert_ms(attributes.get(&quot;elapsedtime&quot;)),
              math.trunc(time.time()),
              attributes.get(&quot;status&quot;),
              attributes.get(&quot;message&quot;),
              attributes.get(&quot;tags&quot;),
          ),
      )
  </code></pre>
  <p>Now similarly I want to write the update query, currently written like this:</p>
  <pre class="lang-py prettyprint-override"><code>    cursor.execute(
          f&quot;UPDATE test_run SET status='{test_run_status}', &quot;
          f&quot;project_name='{project_name_metadata}', &quot;
          f&quot;total_time_in_ms={total_execution_time}, &quot;
          f&quot;total_time_in_hr_min_sec='{convert_ms(total_execution_time)}' &quot;
          f&quot;WHERE run_id={run_id_from_test_run}&quot;
      )
  </code></pre>
  <p>similar to the insert query. I have tried a lot of permutation combination, but wasn't able to achieve what I was looking for. I have already tried searching stackOverflow, but couldn't find a suitable answer for this. If this has been previously answered please do link me to it.</p>
  <p>Edit This is what I tried:</p>
  <pre class="lang-py prettyprint-override"><code>    sql = &quot;UPDATE test_run SET status = %s, project_name = %s, total_time_in_ms = %d, total_time_in_hr_min_sec = %s &quot; \
            &quot;WHERE run_id = %d&quot;
      val = ('{test_run_status}', '{project_name_metadata}', {total_execution_time}, '{convert_ms(total_execution_time)}',
             {run_id_from_test_run})
  cursor.execute(sql, val)
  </code></pre>
  <p>And I got the error as:</p>
  <blockquote>
  <p>ProgrammingError: can't adapt type 'set'</p>
  </blockquote>