Skip to content

Instantly share code, notes, and snippets.

@scuddalo
Created September 5, 2019 20:53
Show Gist options
  • Save scuddalo/3c54bdad1ed9536a33d4abafbe7c9b66 to your computer and use it in GitHub Desktop.
Save scuddalo/3c54bdad1ed9536a33d4abafbe7c9b66 to your computer and use it in GitHub Desktop.
alter table aiclaims.di_prediction add column claim_version_id UUID references aiclaims.di_claim_version (claim_version_id) deferrable initially deferred;
CREATE OR REPLACE FUNCTION update_prediction_claim_version()
RETURNS VOID AS $$
DECLARE
rec RECORD;
BEGIN
FOR rec IN SELECT
DISTINCT c1.claim_version_id,
c0.claim_number
FROM aiclaims.di_claim_latest_version c1
INNER JOIN aiclaims.di_prediction c0 ON (c0.claim_number = c1.claim_number)
LOOP
UPDATE aiclaims.di_prediction set claim_version_id = rec.claim_version_id where claim_number = rec.claim_number;
END LOOP;
END;
$$ LANGUAGE plpgsql;
select update_prediction_claim_version();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment