On Sun, 2012-06-17 at 10:21 +0930, Michael Rowan wrote: > Using PostgreSQL 9.1 I have created my first function. Heres the create statement reported by pgAdminIII: > > CREATE OR REPLACE FUNCTION detect_branch(integer) > RETURNS integer AS ... > Works well. > > However, if I try to create a trigger: > CREATE TRIGGER run_detect_branch > AFTER UPDATE OR INSERT ON branch > FOR EACH ROW > EXECUTE PROCEDURE detect_branch() > > I get an error "function detect_branch() does not exist". 1. You need to write your function in a different language. sql is meant for very simple functions. Try plpgsql: http://www.postgresql.org/docs/9.2/static/plpgsql.html 2. The function should have return type TRIGGER and must be declared to take no arguments: http://www.postgresql.org/docs/9.2/static/sql-createtrigger.html Also, see: http://www.postgresql.org/docs/9.2/static/plpgsql-trigger.html for some examples. Regards, Jeff Davis
pgsql-novice by date:
Соглашаюсь с условиями обработки персональных данных