Thread: can not create trigger with parameter
Hi,
I'm having trouble getting a trigger to use a parameter, as in the
following simplified example:
CREATE FUNCTION fun_version_table(varchar)
RETURNS opaque
AS 'DECLARE
in_table_name ALIAS FOR $1;
v_counter integer;
BEGIN
SELECT INTO v_counter counter FROM version_table
WHERE table_name = in_table_name;
-- do something in here
RETURN new;
END;'
LANGUAGE 'plpgsql';
CREATE TRIGGER trig_deg_master
AFTER
INSERT OR UPDATE OR DELETE
ON author
FOR EACH ROW
EXECUTE PROCEDURE fun_version_table('degree_master');
Function gets created successfully.But
when I create trigger I get an error:
ERROR:CreateTrigger: function fun_version_table() does not exist
I've created triggers/functions with no parameters and they work fine.
The Postgresql book has some examples of functions with paramters, but
I cannot find anywhere a trigger which calls a function with parameters,
although the users manual indicates that parameters are allowed in the
syntax for CREATE TRIGGER.
Regards,
Rahul
From: pgsql-novice-owner@postgresql.org [mailto:pgsql-novice-owner@postgresql.org] On Behalf Of Rahul Patil
Sent: Thursday, December 15, 2005 6:57 AM
To: pgsql-novice@postgresql.org
Subject: [NOVICE] can not create trigger with parameter
Hi,
I'm having trouble getting a trigger to use a parameter, as in the
following simplified example:
CREATE FUNCTION fun_version_table(varchar)
RETURNS opaque
AS 'DECLARE
in_table_name ALIAS FOR $1;
v_counter integer;
BEGIN
SELECT INTO v_counter counter FROM version_table
WHERE table_name = in_table_name;
-- do something in here
RETURN new;
END;'
LANGUAGE 'plpgsql';
CREATE TRIGGER trig_deg_master
AFTER
INSERT OR UPDATE OR DELETE
ON author
FOR EACH ROW
EXECUTE PROCEDURE fun_version_table('degree_master');
Function gets created successfully.But
when I create trigger I get an error:
ERROR:CreateTrigger: function fun_version_table() does not exist
I've created triggers/functions with no parameters and they work fine.
The Postgresql book has some examples of functions with paramters, but
I cannot find anywhere a trigger which calls a function with parameters,
although the users manual indicates that parameters are allowed in the
syntax for CREATE TRIGGER.
Regards,
Rahul