Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot update table Temp Table because it does not have a replica identity and publishes updates in Postgres

I used Postgres Database with replication.
I have used temp table in postgres function. I unable to update Temp Table while updating it through join.

Below is Postgres query(tempallergyupdates is temp table):

 drop table if exists tempallergyupdates;
 create temp table tempallergyupdates(patientallergyid int,updateid int, newupdateid int);
 update tempallergyupdates set patientallergyid = 1;

Above query throws bellow exception:

cannot update table "tempallergyupdates" because it does not have a replica identity and publishes updates

like image 333
Nayan Rudani Avatar asked Mar 05 '23 01:03

Nayan Rudani


1 Answers

We just encountered this and found a solution. It turns out that PostgreSQL does not like tables, even temp tables, that lack a primary key where replication is involved. So either add one to your temp table or use a statement like this after creating the table:

ALTER TABLE table_name REPLICA IDENTITY FULL;
like image 66
ktekinay Avatar answered Apr 27 '23 07:04

ktekinay