From 5ce69011c47010e77d9471bce071b274385312b0 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 25 Sep 2018 13:47:37 -0400 Subject: [PATCH] update fspr to show roll was done --- schema/functions/rollforward.sql | 49 +++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/schema/functions/rollforward.sql b/schema/functions/rollforward.sql index 708785b..681f9f2 100644 --- a/schema/functions/rollforward.sql +++ b/schema/functions/rollforward.sql @@ -84,21 +84,38 @@ BEGIN ) select * from rf ) - INSERT INTO - evt.bal - SELECT - acct - ,id - ,obal - ,debits - ,credits - ,cbal - FROM - bld - ON CONFLICT ON CONSTRAINT bal_pk DO UPDATE SET - obal = EXCLUDED.obal - ,debits = EXCLUDED.debits - ,credits = EXCLUDED.credits - ,cbal = EXCLUDED.cbal; + ,ins AS ( + INSERT INTO + evt.bal + SELECT + acct + ,id + ,obal + ,debits + ,credits + ,cbal + FROM + bld + ON CONFLICT ON CONSTRAINT bal_pk DO UPDATE SET + obal = EXCLUDED.obal + ,debits = EXCLUDED.debits + ,credits = EXCLUDED.credits + ,cbal = EXCLUDED.cbal + RETURNING * + ) + ,touched AS ( + SELECT DISTINCT + fspr + FROM + ins + ) + UPDATE + evt.fspr f + SET + prop = f.prop || '{"rf":"global"}'::jsonb + FROM + touched t + WHERE + t.fspr = f.id; END; $func$; \ No newline at end of file