Trigger (Calling a Procedure)

Started by Harpreet Dhaliwalover 19 years ago4 messagesgeneral
Jump to latest
#1Harpreet Dhaliwal
harpreet.dhaliwal01@gmail.com

Hi,

I'm trying to create a trigger with the following definition:

CREATE TRIGGER insert_price_change AFTER INSERT OR DELETE OR UPDATE ON
raw_email
FOR EACH ROW EXECUTE PROCEDURE add_one(1);

Procedure / Function add_one has the following definition

CREATE FUNCTION add_one(integer) RETURNS integer
AS '/usr/local/pgsql/jsb/add_one', 'add_one'
LANGUAGE C STRICT;

function add_one is running fine.

When I try to create the trigger insert_price_change, it throws me the
follwoing error:

ERROR: function add_one() does not exist

However, I can see function add_one(int4) as one of the functions in
pgadmin.

Don't know whats going on wrong.

Thanks,

~Harpreet

#2Michael Fuhr
mike@fuhr.org
In reply to: Harpreet Dhaliwal (#1)
Re: Trigger (Calling a Procedure)

On Wed, Aug 16, 2006 at 01:35:47AM -0400, Harpreet Dhaliwal wrote:

I'm trying to create a trigger with the following definition:

CREATE TRIGGER insert_price_change AFTER INSERT OR DELETE OR UPDATE ON
raw_email
FOR EACH ROW EXECUTE PROCEDURE add_one(1);

Procedure / Function add_one has the following definition

CREATE FUNCTION add_one(integer) RETURNS integer
AS '/usr/local/pgsql/jsb/add_one', 'add_one'
LANGUAGE C STRICT;

function add_one is running fine.

When I try to create the trigger insert_price_change, it throws me the
follwoing error:

ERROR: function add_one() does not exist

Trigger functions must return type "trigger" and they must be
declared with no arguments. You can pass an argument as in your
CREATE TRIGGER statement but a trigger function receives its arguments
differently than an ordinary function. See the Triggers chapter
in the documentation, especially "Writing Trigger Functions in C":

http://www.postgresql.org/docs/8.1/interactive/triggers.html

Unless you need to use C I'd suggest using PL/pgSQL. Even if you
do need to use C I'd recommend practicing with PL/pgSQL to learn
the basics with a simpler language.

http://www.postgresql.org/docs/8.1/interactive/plpgsql-trigger.html

--
Michael Fuhr

#3Harpreet Dhaliwal
harpreet.dhaliwal01@gmail.com
In reply to: Michael Fuhr (#2)
Re: Trigger (Calling a Procedure)

I got your point.
however, my requirement is something like this.
The trigger shold start another function (a stored procedure) after any
event is fired.

how do I accomplish this goal?

Harpreet

Show quoted text

On 8/16/06, Michael Fuhr <mike@fuhr.org> wrote:

On Wed, Aug 16, 2006 at 01:35:47AM -0400, Harpreet Dhaliwal wrote:

I'm trying to create a trigger with the following definition:

CREATE TRIGGER insert_price_change AFTER INSERT OR DELETE OR UPDATE ON
raw_email
FOR EACH ROW EXECUTE PROCEDURE add_one(1);

Procedure / Function add_one has the following definition

CREATE FUNCTION add_one(integer) RETURNS integer
AS '/usr/local/pgsql/jsb/add_one', 'add_one'
LANGUAGE C STRICT;

function add_one is running fine.

When I try to create the trigger insert_price_change, it throws me the
follwoing error:

ERROR: function add_one() does not exist

Trigger functions must return type "trigger" and they must be
declared with no arguments. You can pass an argument as in your
CREATE TRIGGER statement but a trigger function receives its arguments
differently than an ordinary function. See the Triggers chapter
in the documentation, especially "Writing Trigger Functions in C":

http://www.postgresql.org/docs/8.1/interactive/triggers.html

Unless you need to use C I'd suggest using PL/pgSQL. Even if you
do need to use C I'd recommend practicing with PL/pgSQL to learn
the basics with a simpler language.

http://www.postgresql.org/docs/8.1/interactive/plpgsql-trigger.html

--
Michael Fuhr

#4Harpreet Dhaliwal
harpreet.dhaliwal01@gmail.com
In reply to: Harpreet Dhaliwal (#3)
Re: Trigger (Calling a Procedure)

Its actually something like the trigger should start a C function after
insert and the C function has the ECPG code for some more inserts.
Its similar to the way we dynamically load a shared library while executing
a stored procedure, as in , executing a fucntion in C file using stored
procedure/ function.

Harpreet

Show quoted text

On 8/16/06, Harpreet Dhaliwal <harpreet.dhaliwal01@gmail.com> wrote:

I got your point.
however, my requirement is something like this.
The trigger shold start another function (a stored procedure) after any
event is fired.

how do I accomplish this goal?

Harpreet

On 8/16/06, Michael Fuhr <mike@fuhr.org> wrote:

On Wed, Aug 16, 2006 at 01:35:47AM -0400, Harpreet Dhaliwal wrote:

I'm trying to create a trigger with the following definition:

CREATE TRIGGER insert_price_change AFTER INSERT OR DELETE OR UPDATE ON
raw_email
FOR EACH ROW EXECUTE PROCEDURE add_one(1);

Procedure / Function add_one has the following definition

CREATE FUNCTION add_one(integer) RETURNS integer
AS '/usr/local/pgsql/jsb/add_one', 'add_one'
LANGUAGE C STRICT;

function add_one is running fine.

When I try to create the trigger insert_price_change, it throws me the

follwoing error:

ERROR: function add_one() does not exist

Trigger functions must return type "trigger" and they must be
declared with no arguments. You can pass an argument as in your
CREATE TRIGGER statement but a trigger function receives its arguments
differently than an ordinary function. See the Triggers chapter
in the documentation, especially "Writing Trigger Functions in C":

http://www.postgresql.org/docs/8.1/interactive/triggers.html

Unless you need to use C I'd suggest using PL/pgSQL. Even if you
do need to use C I'd recommend practicing with PL/pgSQL to learn
the basics with a simpler language.

http://www.postgresql.org/docs/8.1/interactive/plpgsql-trigger.html

--
Michael Fuhr