plpgsql trigger function with arguments - Mailing list pgsql-general

From Karl O. Pinc
Subject plpgsql trigger function with arguments
Date
Msg-id 20040302213527.E3302@mofo.meme.com
Whole thread Raw
Responses Re: plpgsql trigger function with arguments
List pgsql-general
I'm sure I saw something like this on the postgresql web
site but the the search function is down in the documentation
area.

I'm unable to pass a function arguments in a CREATE
TRIGGER statement.

What am I doing wrong here?

CREATE FUNCTION pregs_func (VARCHAR(15))
   RETURNS trigger
   LANGUAGE plpgsql
   AS '
   DECLARE
   trigger_type ALIAS FOR $1;

   BEGIN
     IF trigger_type = ''insert'' THEN
       ...
     END IF;
   END;
';

CREATE TRIGGER pregs_insert_trigger
   AFTER INSERT
   ON pregs FOR EACH ROW
   EXECUTE PROCEDURE pregs_func('insert');

CREATE TRIGGER pregs_update_trigger
   AFTER UPDATE
   ON pregs FOR EACH ROW
   EXECUTE PROCEDURE pregs_func('update');

The CREATE TRIGGER statements return:
ERROR:  CreateTrigger: function pregs_func() does not exist


I tried doing variations on:
   create trigger pregs_insert_trigger after insert on pregs
   for each row execute procedure
   pregs_func (cast('insert' as varchar(15)));

thinking that I don't have the right function because the
datatypes don't match, but I get:
ERROR:  parser: parse error at or near "cast" at character 106

PostgreSQL 7.3.

Thanks,

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                  -- Robert A. Heinlein

pgsql-general by date:

Previous
From: Joe Conway
Date:
Subject: Re: Max/min of 2 values function, plpgsql efficency?
Next
From: "Karl O. Pinc"
Date:
Subject: Re: constraints