Re: Problem creating trigger - Mailing list pgsql-novice

From Jeff Davis
Subject Re: Problem creating trigger
Date
Msg-id 1339897956.14729.8.camel@jdavis
Whole thread Raw
In response to Problem creating trigger  (Michael Rowan <mike.rowan@internode.on.net>)
List 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



pgsql-novice by date:

Previous
From: Michael Rowan
Date:
Subject: Problem creating trigger
Next
From: Jeff Davis
Date:
Subject: Re: Planning a Large RDBMS