how transform buttress value incrementally
i'm experimenting personal financial application, i'm pondering proceed take transform controlling balances entering transaction an account.
currently proceed i'm controlling involves retrieving annals some-more new inserted/modified one, incrementing controlling balance.
for example, given following transactions:
t1 date = 2008-10-21, volume = 500, controlling change = 1000
t2 date = 2008-10-22, volume = 300, controlling change = 1300
t3 date = 2008-10-23, volume = 100, controlling change = 1400
...
now suspect i insert transaction between t1 t2, following t2 unbroken sell need controlling balances adjusted.
hehe, i wrote question, i cruise i know answer... i'll leave here box helps someone else (or maybe there's even improved approach?)
first, i controlling change before transaction, case, t1. following i transform following sell (which consolidate new one):
update transactions
set running_balance = running_balance + <amount>
where date > <t1.date>
the wholly emanate i instead storing wholly date, i'll have store too. although, occur twin sell accurate same date/time?
ps: i'd move solutions involving propietary features, i'm controlling both postgresql sqlite... nonetheless postgre-only fortitude useful too.
Comments
Post a Comment