I try to handle this situation in a PostgreSQL database. I insert data to a table called "Invoice" by programming:
invoice_id account_id amount current
1 a2322 3 null
2 a2322 10 null
3 b4354 1 null
4 c8099 2 null
5 a2322 4 null
6 b4354 -5 null
so, when a new record is inserted, I want to update the current field with the sum of amounts like this:
invoice_id account_id amount current
1 a2322 3 null
2 a2322 10 null
3 b4354 1 null
4 c8099 2 null
5 a2322 4 null
6 b4354 -5 null
7 a2322 4 result(sum of amount: 21)
8 b4354 3 result(sum of amount: -1)
Can I do that inside PostgreSQL without programming?