How to perform an upsert (insert or update) operation in PostgreSQL using the INSERT ON CONFLICT.



How to perform an upsert (insert or update) operation in PostgreSQL using the INSERT ON CONFLICT.

How to perform an upsert (insert or update) operation in PostgreSQL using the INSERT ON CONFLICT.

How to use the INSERT ON CONFLICT construct in PostgreSQL.

PostgreSQL will allow you for perform an insert statement using the ON CONFLICT clause, which will switch between doing an insert, or if the insert statement will fail the primary key constraint, perform an update statement.

The DO UPDATE, identifies a primary key violation, and swaps over to perform an UPDATE statement.

The DO NOTHING option skips the conflicted row, allowing the transaction to complete with other valid rows.

How to use `INSERT ON CONFLICT` to upsert data in PostgreSQL

#softwareNuggets; #upsert; #insertOnConflict, #postgreSQL, #postgresqlDeveloper, #postgreSqlTraining