From cd29ccefabde30e9e7dc8c5ee850d6eb76cb72c4 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 24 Sep 2018 00:07:05 -0400 Subject: [PATCH] functional but checks max for all bal every time --- db_deploy.sql | 8 ++++++-- schema/triggers/gl_insert.sql | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/db_deploy.sql b/db_deploy.sql index 4b0325c..8c61b10 100644 --- a/db_deploy.sql +++ b/db_deploy.sql @@ -205,12 +205,16 @@ CREATE OR REPLACE FUNCTION evt.gl_insert() RETURNS trigger ,list AS ( SELECT acct - ,min(lower(dur)) minp - ,max(lower(dur)) maxp + ,least(min(lower(dur)),min(lower(g.dur))) minp + ,greatest(max(lower(dur)),max(lower(g.dur))) maxp FROM ins b INNER JOIN evt.fspr f ON f.id = b.fspr + LEFT OUTER JOIN evt.bal e ON + e.acct = b.acct + LEFT OUTER JOIN evt.fspr g ON + g.fspr = e.id GROUP BY acct ) diff --git a/schema/triggers/gl_insert.sql b/schema/triggers/gl_insert.sql index de390d6..dbb6abe 100644 --- a/schema/triggers/gl_insert.sql +++ b/schema/triggers/gl_insert.sql @@ -29,15 +29,19 @@ CREATE OR REPLACE FUNCTION evt.gl_insert() RETURNS trigger ) ,list AS ( SELECT - acct - ,min(lower(dur)) minp - ,max(lower(dur)) maxp + b.acct + ,least(min(lower(f.dur)),min(lower(g.dur))) minp + ,greatest(max(lower(f.dur)),max(lower(g.dur))) maxp FROM ins b INNER JOIN evt.fspr f ON f.id = b.fspr + LEFT OUTER JOIN evt.bal e ON + e.acct = b.acct + LEFT OUTER JOIN evt.fspr g ON + e.fspr = g.id GROUP BY - acct + b.acct ) ,seq AS ( WITH RECURSIVE rf (acct, minp, maxp, id, dur, obal, debits, credits, cbal) AS