Creating a trigger function - Mailing list pgsql-general

From Peter Erickson
Subject Creating a trigger function
Date
Msg-id 9sGdnVnmCewn6fLdRVn-uw@comcast.com
Whole thread Raw
Responses Re: Creating a trigger function
List pgsql-general
I am running postgresql 7.4.2 and having problems creating a trigger
function properly. I keep getting the following error:

ERROR: OLD used in query that is not in rule

I have a table called journal_entries with a foreign key to a table
called journals. When a entry is added to journal_entries, I am trying
to get it to update the 'mtime' field of the corresponding entry in the
journals table.

Can anyone help me with this problem? If you need more information,
please let me know.

CREATE OR REPLACE FUNCTION public.update_journal_mtime()
   RETURNS trigger AS
'
   DECLARE
     curtime TIMESTAMP;
   BEGIN
     curtime := \'now\';
     IF OLD IS NOT NULL THEN
       UPDATE journals SET mtime = curtime WHERE id = OLD.journ_id;
     END IF;
     IF NEW IS NOT NULL THEN
       UPDATE journals SET mtime = curtime WHERE id = NEW.journ_id;
       UPDATE journal_entries SET mtime = curtime WHERE id = NEW.id;
     END IF;
     RETURN null;
   END;
'
   LANGUAGE 'plpgsql' VOLATILE;

CREATE TRIGGER update_mtime_trigger
   AFTER INSERT OR UPDATE OR DELETE
   ON public.journal_entries
   FOR EACH ROW
   EXECUTE PROCEDURE public.update_journal_mtime();

pgsql-general by date:

Previous
From: Wes Palmer
Date:
Subject: thread_test.c problems
Next
From: Fernando Schapachnik
Date:
Subject: Re: pg_autovacuum won't make on FreeBSD