title: python: psycopg2: psql: Delete row where condition
body: <p>I'm trying to delete rows from a psql table on a condition.</p>
  
  <p>I want all rows to be deleted if column "TagNaam" equals a variable var_tagnaam.</p>
  
  <p>I've tried the following code and some variants but I can't get it to work.
  There aren't any errors though.</p>
  
  <pre><code>cur.execute("DELETE FROM opc_actuelewaardentags WHERE 'TagNaam' = %s", (var_tagnaam,))
  </code></pre>
  
  <p>Is there something wrong with the syntax?</p>
  
  <p>Edit:
  Maybe it is more clear with additional code, the error might be in the other code?</p>
  
  <pre><code>for i in range(len(taginhoud)):
      (var_tagnaam, var_tagwaarde, var_tagkwaliteit, var_tagtime) = taginhoud[i]
      print (var_tagnaam)
  
      cur.execute("DELETE FROM opc_actuelewaardentags WHERE 'TagNaam' = %s", (var_tagnaam,))
      conn.commit()
  
      cur.execute('INSERT INTO opc_actuelewaardentags ("TagNaam", "TagWaarde", "TagKwaliteit", create_date, write_date) VALUES (%s,%s,%s,now(),now())',
                  (var_tagnaam, var_tagwaarde, var_tagkwaliteit))   
      conn.commit()
  </code></pre>
  
  <p>So what I try to do here is:</p>
  
  <p>Retrieve "var_tagnaam" from list "taginhoud".</p>
  
  <p>Then in table opc_actuelewaardentags find all rows where column "Tagnaam" equals the value in "var_tagnaam". (Should be a string)</p>
  
  <p>Then delete those rows where "Tagnaam" = "var_tagnaam". This part doesn't work.</p>
  
  <p>Then insert new rows with data. This part works.</p>
  
  <p>Could this code be wrong to do what I want?</p>
  
  <p>I have tried many things already to solve the upper/lower case problem.</p>
  
  <p>Edit 2:Query in pgadmin worked, trying to do the same thing in python:</p>
  
  <p>I ran this query in pgadmin and it deleted the rows:</p>
  
  <pre><code>delete FROM opc_actuelewaardentags where "TagNaam" = 'Bakkerij.Device1.DB100INT8';
  </code></pre>
  
  <p>My attempt to make it as similar as possible in python:</p>
  
  <pre><code>var_tagnaam2 = "'"+var_tagnaam+"'"
  cur.execute("DELETE FROM opc_actuelewaardentags WHERE \"TagNaam\" = %s", (var_tagnaam2,))
  conn.commit()
  </code></pre>
  
  <p>Tried to escape the double quotes in attempt to make it the same as in pgadmin.</p>