'How to use on conflict update to just replace the row?
Having a DB with columns: date_num, name, c, o, v, where date_num, name, are unique.
When insert, if the date_num, and name columns combination already exist, I want to replace the whole row as is.
df.to_sql('temp_insert', connection, if_exists ='replace')
sql = (
'''INSERT INTO {table_name} ({cols})
SELECT {cols} FROM temp_insert
ON CONFLICT DO UPDATE'''.format(table_name=table_name,cols=cols)
)
after DO UPDATE, what do I have to SET to just replace that row ?
ON CONFLICT DO UPDATE SET .... ?
Solution 1:[1]
You can use the EXCLUDE clause to do some computes, for example:
DO UPDATE SET your_column = EXCLUDED.your_column;
from the doc
Note that the special excluded table is used to reference values originally proposed for insertion:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anthony Sotolongo |
