Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Sean Hussey
RE: writing triggers in postgres using ruby [ reply ]  
2007-05-25 15:39
You might want to check in another forum for an answer to this question. This is only for Net::LDAP questions.

By: venkat venkat
writing triggers in postgres using ruby [ reply ]  
2007-05-25 11:37
Hi folks,
I am a new bee to ruby/postgresql.I am using postgresql as my database server.Today, in my project I came accross a point where I need to write a trigger in plruby.In one of the materials I found the following sample code

CREATE FUNCTION trigfunc_modcount() RETURNS TRIGGER AS '
case tg["op"]
when PL::INSERT
new[args[0]] = 0
when PL::UPDATE
new[args[0]] = old[args[0]].to_i + 1
else
return PL::OK
end
new
' LANGUAGE 'plruby';

CREATE TABLE mytab (num int4, modcnt int4, descr text);

CREATE TRIGGER trig_mytab_modcount BEFORE INSERT OR UPDATE ON mytab
FOR EACH ROW EXECUTE PROCEDURE trigfunc_modcount('modcnt');

but the blog didnot specify where should i place this stuff and how I call it and etc...I am a little confused.

Any help appreciated.Thanks in advance
venkat,
venkat.bagam@rknowsys.com