Constraint on an aggregate? (need help writing trigger, i think..)

Поиск
Список
Период
Сортировка
От Isak Hansen
Тема Constraint on an aggregate? (need help writing trigger, i think..)
Дата
Msg-id 6b9e1eb20607260313h1d142d44od650ab3b6e23023@mail.gmail.com
обсуждение исходный текст
Ответы Re: Constraint on an aggregate? (need help writing trigger,
Список pgsql-general
I have the following two tables:

create table a (
  id serial primary key,
);
create table b (
  id serial primary key,
  a_id int4 references a (id),
  amount decimal(16, 2)
);

and would like a constraint to guarantee that "sum(b.amount) = 0 group
by b.a_id".


From my testing so far, and this thread:

<http://groups.google.com/group/comp.databases/browse_thread/thread/c2ce2d61eecf5c6c/1e0fa71282aea7d8#1e0fa71282aea7d8>,
i think a trigger is the way to go.

Problem is, i have no idea where to go from here. Getting the model
nearly to to 3NF and writing some simple queries is about the extent
of my db-related skillset..

Anyone feel the calling..? ;)


Also, how would this kind of check affect performance? Table 'b' is
our ledger table, busiest one in the app i assume, while 'a' groups
related transactions and holds common info. We inherited the term
voucher for 'a', anyone know if that is(n't) appropriate?

If someone are interested, the actual tables are here:
a: http://trac.lodo.no/wiki/vouchers
b: http://trac.lodo.no/wiki/voucher_lines


Any feedback appreciated,
Isak

В списке pgsql-general по дате отправления:

Предыдущее
От: "A. Kretschmer"
Дата:
Сообщение: Re: question about default value and timestamp
Следующее
От: Joachim Wieland
Дата:
Сообщение: Re: ECPG. Badly stuck