Passing Arguments to a trigger function(Problem)

From: "Jasbinder Bali" <jsbali(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Passing Arguments to a trigger function(Problem)
Date: 2006-08-22 17:48:06
Message-ID: a47902760608221048s6ffc3a8fy3650a68b187dfcc1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,
I have a scenario in which I need to pass arguments to a trigger function.
The scenario is as follows:

I have a raw_email table.

A trigger is written after every insert for each row.
Trigger function calls another procedure (SP_parse_email) internally.

Now, SP_parse_email needs 2 arguments (id, raw_email) that comes from the
newly inserted row in the raw_email table.

This means, i need to propogate new.id and new.raw_email fields newly
inserted in the raw_email table.

For this purpose, i write my trigger function as follows:

-------------------------------------------------------

CREATE OR REPLACE FUNCTION new_trigger_func()
RETURNS "trigger" AS
$BODY$
BEGIN
PERFORM sp_parse_email(TG_ARGV[0], TG_ARGV[1]);
RETURN NEW;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION new_trigger_func() OWNER TO postgres;

-------------------------------------------------------

I run it and works fine.

Now, I write my trigger as follows:

------------------------------------------------------------------------
CREATE TRIGGER new_test_trigger
AFTER INSERT
ON raw_email
FOR EACH ROW
EXECUTE PROCEDURE new_trigger_func(NEW.id);
------------------------------------------------------------------------

Running this script gives me the following error:

ERROR: syntax error at or near "NEW" at character 115

Don't know what is the correct way to do this.

Thanks and regards,
~Jas

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Brian Hurt 2006-08-22 17:52:31 Re: problem with single quote : '
Previous Message Srinivas Iyyer 2006-08-22 17:44:09 problem with single quote : '