0

Is it possible to achieve Upsert in Postgres without using the On Conflict clause?

I have a requirement where I converted a normal table into a partitioned table with a partition key that was not part of the Primary Key when the table was non-partitioned.

Since the partition key is added to the primary key column list now, my Upsert statements are failing as the On Conflict clause is missing the partition key. But as per the requirement, I cannot add the partition key to the On Conflict clause as I will have more than one row for the previous primary key column combination in the partitioned table.

Hence, I want Upsert to be achieved without the On Conflict clause. Can someone suggest what alternatives would work.

Mano
  • 601
  • 10
  • 32
  • 3
    With Postgres 15 you could use a MERGE statement. Or use the [solutions](https://stackoverflow.com/questions/17267417) that were used prior to Postgres 9.5 - but beware of concurrency pitfalls –  Jan 30 '23 at 15:11

0 Answers0