title: PostGres SQL Update Values based on List of IDs or Primary Keys in another table
body: <p>I have a list of IDs [1,5,8,...].  I also have a table (TableA) that has 100 rows (which matches my list of IDs exactly).  I have another table (TableB) that has tons of rows (2000) and I want to update one column (True/False) based on if the Primary Key exists in TableA's primary keys (or my python list of IDs - which is the same).  </p>
  
  <p>Currently I loop through my list of IDs and just do a simply update statement (below is python code):</p>
  
  <pre><code>for id in ID_List:
       cur.execute('update TableB set "Column1"=%s where "ID"=%s', (False,id))
  </code></pre>
  
  <p>This works fine - but I am curious if there is a single line code I could use rather than a loop.  Something like:</p>
  
  <pre><code>cur.execute('update TableB set "Column1"=False where "ID" in ID_List')
  or 
  cur.execute('update TableB set "Column1"=False where "ID" in TableA.keys()'
  </code></pre>
  
  <p>and all the rows in the ID_List would update quickly.  I can't use ">" or "&lt;" because the IDs might not all be greater than or smaller than a specific number.  I may want to change IDs (3,6,9) but not (4,7,8).  </p>