insert on insert/update

Поиск
Список
Период
Сортировка
От Haris Susanto
Тема insert on insert/update
Дата
Msg-id 377064F8.88F0DFC@dnet.net.id
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Min Qiu
Дата:
Сообщение: Are int4/int8 ops defined?
Следующее
От: Min Qiu
Дата:
Сообщение: Re: [SQL] Are int4/int8 ops defined?