Обсуждение: creating a trigger to write to a different table

Поиск
Список
Период
Сортировка

creating a trigger to write to a different table

От
Peter Choe
Дата:
can i use pl/pgsql to write a trigger to update a separate table?

for example if i have a table student:
name    text,
id    text,
group    int,
stat    int,

and another table status:
stat    text
group    int
count    int

and i update the stat in the student table, can i update the count
column in the status table to reflect the change.  in the documents, i
just see triggers used on one table.

peter choe

Re: creating a trigger to write to a different table

От
Stephan Szabo
Дата:
On Thu, 22 Mar 2001, Peter Choe wrote:

> can i use pl/pgsql to write a trigger to update a separate table?

You should be able to.  You can use update, etc, from the trigger.

For example a simple summing one might be (not really tested)
create function summer() returns opaque
as '
begin;
 update table2 set val=val+NEW.val where id=NEW.id;
 return NEW;
end;
' language 'plpgsql';
)

create trigger tr after insert on table1 for each row execute
procedure summer();