pglogical icon indicating copy to clipboard operation
pglogical copied to clipboard

How to sync associated table records

Open Nilanth opened this issue 2 years ago • 5 comments

How to sync associated table records using replication_set_add_table?

I have tables like Users, Post, and Comments. We need to sync the Comments related to a user.

Table Schema

Users id, name, email

Posts id, name, user_id

Comments id, comment, post_id

I tried with the below query but it doesn't work.

SELECT pglogical.replication_set_add_table(set_name := 'replication_set', relation := 'comments', synchronize_data := true, row_filter := 'post_id in (select id from posts where user_id = 1)');

Nilanth avatar Aug 29 '22 07:08 Nilanth

This kind of thing is not supported. A row filter can only look at its own table.

petere avatar Sep 02 '22 12:09 petere

This kind of thing is not supported. A row filter can only look at its own table.

Thanks, Do u suggest any other tools for this case?

Nilanth avatar Sep 02 '22 12:09 Nilanth

Sync related tables as whole units. Sync the comments table, and user tables in their entirety. If you need filters like the one you showed here, you need a different tool.

bonesmoses avatar Sep 02 '22 13:09 bonesmoses

@bonesmoses Can you suggest any tool for this?

Nilanth avatar Sep 05 '22 10:09 Nilanth

Another alternative is to modify your schema to include user_id into the comments table. Hence, you can use a row_filter: user_id = 1.

eulerto avatar Nov 09 '22 12:11 eulerto