require some suggestion to write trigger function

From: Jignesh Shah <jignesh(dot)shah1980(at)gmail(dot)com>
To: postgresql novice <pgsql-novice(at)postgresql(dot)org>
Subject: require some suggestion to write trigger function
Date: 2009-09-07 09:33:09
Message-ID: c11950270909070233r642ef8aap4b539cb2319cbf1f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi, could any one please help me with below situation. Thanks for your time
in advance.

I have two tables Foo1(c1,c2,c3) and Foo2(x1,x2,x3). I have written trigger
for Foo1 and it is working fine. The trigger updates the log table when new
insertion happened in Foo1. For this, I have used below code.

CREATE OR REPLACE FUNCTION my_triggert() RETURNS trigger AS $$
$rv = spi_exec_query("insert into logtable VALUES($_TD->{new}{c1},
'$_TD->{new}{c2}','$_TD->{new}{c3}');");
($rv->{processed} == 0 && $rv->{status} eq "SPI_OK_INSERT") ?
elog(INFO, "Success") :
elog(INFO, "Failed");
$$ LANGUAGE plperl;

I have hard coded the columns name c1, c2, c3. Is it possible to get rid of
hard coding c1, c2 and c3 so that I can use same my_trigger function for
Foo2(x1, x2, x3) as well? Any suggestion would be really helpful for me.

Thanks,
Jignesh

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Wood 2009-09-07 15:59:04 Re: problem loading sql to database?
Previous Message Sergey Samokhin 2009-09-06 16:38:19 Re: Runtime parameter holding is_in_transaction state