on ‎2022 Nov 03 8:54 AM
Is it possible to define articles in a publication and let the where clause refer to columns from a foreign table?
For example I have these 2 tables:
create or replace table employees ( empid int, withprovision int, empname varchar(10), departid int);
create or replace table orders ( orderid int, empid int);
I want to let sql remote replicate only the employees who make provision along with their orders, also I want to refer the subscription by from a foreign table.
My scripts looks like this:
create publication dba.mypub (table employees where withprovision = 1 subscribe by departid, table orders where exists (select 1 from employees where withprovision = 1 and orders.empid = employees.empid subscribe by ????);
Table employees works exactly as I want (where clause and subscribe by do what I need).
Table orders: the where clause acts as where 1 = 2 and I don't know how to write the subscribe by...
Is this generally possible with SQL Remote?
Request clarification before answering.
One approach is to use a join within your WHERESUBSCRIBE BY subquery, i.e. for say, table order_items, you would use something like
subscribe by
(select e.departid
from order_items oi
inner join orders o on oi.order_id = o.id
inner join employees e on o.empid = e.empid
where e.withprovision = 1)
In other words: You can use the same subscribe by condition for all dependent tables but have to join them to the table the subscribe by relates to.
FWIW, this is also (and naturally in a better fashion) documented in the docs:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.