Skip site navigation (1) Skip section navigation (2)

Can triggers update other tables?

From: Rikard <rikard(dot)bosnjakovic(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Can triggers update other tables?
Date: 2011-10-20 00:24:42
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
VERSION = 'PostgreSQL 8.4.2 on i686-pc-linux-gnu, compiled by GCC gcc
(GCC) 3.4.6, 32-bit'

I'm reading at
and but I
cannot solve this problem. The very outline is that I'm having two
tables (in reality there are a lot more), something like this:

  SUMMARY ( id integer, num_stores integer; );
  ITEMS ( id serial PRIMARY KEY; name text; some_reference integer,
some_value smallint; ).

When a row is inserted in ITEMS, I want to launch a trigger that
issues a "UPDATE num_stores SET num_stores=(SELECT count(*) FROM items
WHERE id = <>) where id = <>".
Triggers seem to be run on functions returning plpgsql and I don't
know how to issue ordinary SQL-commands in SQL, so I don't know how to
reference these two tables in a single trigger.

Is it possible? If yes, which section of the manual is the place for
me to read up on?


pgsql-novice by date

Next:From: Basil BourqueDate: 2011-10-20 01:08:00
Subject: Query on DATETIME for a date (the whole day)
Previous:From: Andy HalsallDate: 2011-10-19 08:45:38
Subject: Re: Functions returns to libpq with wrong column split

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group