title: Multi-row UPSERT (INSERT or UPDATE) from Python
body: <p>I am currently executing the simply query below with python using pyodbc to insert data in SQL server table:</p>
  
  <pre><code>import pyodbc
  
  table_name = 'my_table'
  insert_values = [(1,2,3),(2,2,4),(3,4,5)]
  
  cnxn = pyodbc.connect(...)
  cursor = cnxn.cursor()
  cursor.execute(
      ' '.join([
          'insert into',
          table_name,
          'values',
          ','.join(
              [str(i) for i in insert_values]
          )
      ])
  )
  cursor.commit()
  </code></pre>
  
  <p>This should work as long as there are no duplicate keys (let's assume the first column contains the key). However for data with duplicate keys (data already existing in the table) it will raise an error.
  How can I, in one go, insert multiple rows in a SQL server table using pyodbc such that data with duplicate keys simply gets updated.</p>
  
  <p>Note: There are solutions proposed for single rows of data, however, I would like to insert multiple rows at once (avoid loops)!</p>