Triggers

Started by Germán Hüttemann Arzaover 19 years ago3 messagesgeneral
Jump to latest
#1Germán Hüttemann Arza
ghuttemann@gmail.com

Hello, I have this doubt since I started using PostgreSQL, a few months ago.

Why triggers are defined that way? I mean, in others DBMS you simply write:

CREATE TRIGGER <trigger_name> ... bla bla bla
BEGIN
....
END;

Why you should write a function first and then the trigger, which must call
that function?

What are the advantages/disadvantages of that? Where can I find more
information?

--
Germán Hüttemann Arza

#2Chris Mair
chrisnospam@1006.org
In reply to: Germán Hüttemann Arza (#1)
Re: Triggers

Why you should write a function first and then the trigger, which must
call that function?

What are the advantages/disadvantages of that? Where can I find more
information?

The PG way seems very natural to me:
you can write functions that do something and then have many triggers
call that same function.

Also there's not just PL/PGSQL: you might want
to define a function in C or Perl and then have a trigger call it.

Bye, Chris.

--

Chris Mair
http://www.1006.org

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Chris Mair (#2)
Re: Triggers

Chris Mair <chrisnospam@1006.org> writes:

Why you should write a function first and then the trigger, which must
call that function?

... there's not just PL/PGSQL: you might want
to define a function in C or Perl and then have a trigger call it.

Right, that's the real reason: this approach doesn't constrain which
PL you can write your triggers in.

regards, tom lane