CREATE SINK insights.client_to_account_groups_sink AS
SELECT
m.client_id,
m.account_group_id,
m.type
FROM insights.client_to_account_groups_mv AS m
LEFT JOIN insights.clients_with_accounts_mv AS cwa
ON cwa.client_id = m.client_id
WHERE
m.type = 'none' OR NOT cwa.client_id IS NULL
WITH (
connector='postgres',
host='psql-nonprod-uae-derived.postgres.database.azure.com',
port='6432',
user='migration_user',
password='***',
database='adib-int-insights-db',
table='client_to_account_groups_dm',
schema='insights',
type='upsert',
force_compaction='true',
primary_key='client_id,account_group_id,type'
)