I have a table for which when processing records I get either the full record, else only the columns to be updated.
I want to write a query to handle updates but only update the columns with non null values. For example,
Existing table:
1 | John Doe | USA
2 | Jane Doe | UK
Incoming records:
(3, Kate Bill, Canada)
(2, null, USA)
I want to insert the first record and on conflict of key on second record ONLY update the last column.
I'm not sure how to write this using a execute_values method call:
execute_values(cursor, "INSERT INTO user_data\
(id, name, country) VALUES %s ON CONFLICT DO UPDATE SET \
<how to only set non null values here>", vendor_records)
I'm using psycopg2 to execute this.