From: | Jeff Davis <pgsql(at)j-davis(dot)com> |
---|---|
To: | Michael Rowan <mike(dot)rowan(at)internode(dot)on(dot)net> |
Cc: | pgsql-novice novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Problem creating trigger |
Date: | 2012-06-17 01:52:36 |
Message-ID: | 1339897956.14729.8.camel@jdavis |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2012-06-17 06:56:22 | Re: Planning a Large RDBMS |
Previous Message | Jeff Davis | 2012-06-17 01:40:55 | Re: Planning a Large RDBMS |