Skip site navigation (1) Skip section navigation (2)

Re: Passing Arguments to a trigger function(Problem)

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Jasbinder Bali <jsbali(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Passing Arguments to a trigger function(Problem)
Date: 2006-08-22 18:03:42
Message-ID: 20060822110048.B71057@megazone.bigpanda.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Tue, 22 Aug 2006, Jasbinder Bali wrote:

> 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;

The function gets NEW (and some other values) automagically, so you should
just be able to use NEW.id and NEW.raw_email in the function body.  The
argument passing stuff is for passing other constant args into the trigger
(for example potentially to use the same trigger function for slightly
different cases where you can differentiate based on the argument given at
trigger creation).



In response to

pgsql-novice by date

Next:From: Srinivas IyyerDate: 2006-08-22 18:30:41
Subject: Re: problem with single quote : ' Problem solved
Previous:From: Cyrus DowneyDate: 2006-08-22 17:58:08
Subject: Re: problem with single quote : ' [VASCL:A111C2C2718]

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group