insert on insert/update - Mailing list pgsql-sql

From Haris Susanto
Subject insert on insert/update
Date
Msg-id 377064F8.88F0DFC@dnet.net.id
Whole thread Raw
List pgsql-sql
Help me, I have problem to solve the following case :

I have two tables with structure like these :

table_a
date                    id                      type                 amount
---------------------------------
01/06/99          01                     a                        200                         (1)
01/06/99          02                     a                        900                         (2)
05/06/99          01                     b                        300                         (3)
01/07/99          01                     a                        500                         (4)

table_b
date                   id                     balance
------------------------
01/06/99         01                    -200                                                 (A)
01/06/99        02                     -900                                                 (B)
05/06/99         01                    100                                                    (C)
01/07/99         01                    -400                                                 (D)

Everytime I insert a record into table_a or update the value of amount of a record, automatically
postgres insert a record into table_b.

For exampe if I insert a record (4)
Then the value of (D) :
table_b.date same as table_a.date
table_b.id same as  table_a.id
table_b.balance = -200 + 300 + (-500)

Would somebody please tell  me how to make it happen ?

Thanks a lot !



pgsql-sql by date:

Previous
From: Min Qiu
Date:
Subject: Are int4/int8 ops defined?
Next
From: Min Qiu
Date:
Subject: Re: [SQL] Are int4/int8 ops defined?