How to upsert pandas DataFrame to Microsoft SQL Server table?

Update, July 2022: You can save some typing by using this function to build the MERGE statement and perform the upsert for you. SQL Server offers the MERGE statement: import pandas as pd import sqlalchemy as sa connection_string = ( “Driver=ODBC Driver 17 for SQL Server;” “Server=192.168.0.199;” “UID=scott;PWD=tiger^5HHH;” “Database=test;” “UseFMTONLY=Yes;” ) connection_url = sa.engine.URL.create( “mssql+pyodbc”, … Read more

Fast or Bulk Upsert in pymongo

Modern releases of pymongo ( greater than 3.x ) wrap bulk operations in a consistent interface that downgrades where the server release does not support bulk operations. This is now consistent in MongoDB officially supported drivers. So the preferred method for coding is to use bulk_write() instead, where you use an UpdateOne other other appropriate … Read more

serial in postgres is being increased even though I added on conflict do nothing

The reason this feels weird to you is that you are thinking of the increment on the counter as part of the insert operation, and therefore the “DO NOTHING” ought to mean “don’t increment anything”. You’re picturing this: Check values to insert against constraint If duplicate detected, abort Increment sequence Insert data But in fact, … Read more

Does DB2 have an “insert or update” statement?

Yes, DB2 has the MERGE statement, which will do an UPSERT (update or insert). MERGE INTO target_table USING source_table ON match-condition {WHEN [NOT] MATCHED THEN [UPDATE SET …|DELETE|INSERT VALUES ….|SIGNAL …]} [ELSE IGNORE] See: http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/r0010873.htm https://www.ibm.com/support/knowledgecenter/en/SS6NHC/com.ibm.swg.im.dashdb.sql.ref.doc/doc/r0010873.html https://www.ibm.com/developerworks/community/blogs/SQLTips4DB2LUW/entry/merge?lang=en