Search Postgresql Archives

Creating a trigger function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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();

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux