Reputation: 5061
I have a strange requirement, I want to replicate data from table1 of Schema1 to table2 of Schema2 on any change of table1.
I am using postgres, how to achieve this? tables will have exactly same structure
Upvotes: 0
Views: 124
Reputation:
If the table in schema2 should always be an exact copy of the one in schema1, I would simply create a view in schema2 that selects from schema1.
create view schema2.table1
as
select *
from schema1.table1;
You will need to re-create the view if you change the definition of the table in schema1 (but you would need to do that with a replicated copy as well).
Upvotes: 1
Reputation: 11426
Firstly, try to analyze the nature of the workload and your priorities. And will become clearer in what direction to look for a solution.
For example, if you can assume that updates will occur much less frequently than deletions and additions and you have a limited time - implement just simpliest delete, insert triggers and handle update as reinsert in both tables.
Upvotes: 0