Created
January 31, 2025 13:21
-
-
Save Alxandr/fba5a45cb2b7c0aa2bff01cdd190f111 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MERGE INTO register.external_role_assignment era USING ( | |
SELECT | |
p_from_party from_party, | |
p_source "source", | |
a.to_party, | |
a.identifier | |
FROM | |
unnest(p_assignments) a | |
) upd ON era.from_party = upd.from_party | |
AND era.to_party = upd.to_party | |
AND era."source" = upd."source" | |
AND era.identifier = upd.identifier WHEN NOT MATCHED BY SOURCE THEN DELETE WHEN NOT MATCHED BY TARGET THEN INSERT ("source", identifier, from_party, to_party) | |
VALUES | |
( | |
upd."source", | |
upd.identifier, | |
upd.from_party, | |
upd.to_party | |
) | |
RETURNING | |
CASE | |
WHEN merge_action () = 'INSERT' THEN 'added'::register.external_role_assignment_event_type | |
WHEN merge_action () = 'DELETE' THEN 'removed'::register.external_role_assignment_event_type | |
END "type", | |
COALESCE(era.to_party, upd.to_party) to_party, | |
COALESCE(era.identifier, upd.identifier) identifier |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment