I am avoiding duplicates with ON CONFLICT, but I would like to print something and know that a conflict just occurred , how can I do that with the current query ?
connection = engine.connect()
# APPEND TO STAGING TEMP TABLE
df.to_sql('temp_insert', connection, if_exists ='replace')
# STRING OF COMMA SEPARATED COLUMNS IN CASE NOT ALL COLS EXIST
cols = ", ".join(df.columns)
sql = (
'''INSERT INTO {table_name} ({cols})
SELECT {cols} FROM temp_insert
ON CONFLICT DO NOTHING'''.format(table_name=table_name,cols=cols)
)
result = connection.execute(sql) #could I know here ???
connection.close()