How can I write trigger on a columns insert/update?

Поиск
Список
Период
Сортировка
Искать

How can I write trigger on a columns insert/update?

От:
"Dinesh Pandey" <dpandey@secf.com>
Дата:

How can I write trigger on a columns insert/update?

 

 

CREATE TRIGGER mytrigger

BEFORE

INSERT OR UPDATE

          OF mycolumn ON mytable

FOR EACH ROW

          EXECUTE PROCEDURE myfunction();

 

I am getting error “syntax error at or near "OF"

 

Thanks

 

Re: How can I write trigger on a columns insert/update?

От:
Richard Huxton <dev@archonet.com>
Дата:
Dinesh Pandey wrote:
> How can I write trigger on a columns insert/update?
> 
> CREATE TRIGGER mytrigger
> BEFORE
> INSERT OR UPDATE 
>           OF mycolumn ON mytable

You don't I'm afraid. It's not a feature that's supported yet. You have 
to check which column(s) were changed in your functions.

It is on the TODO list though:
   http://www.postgresql.org/docs/faqs.TODO.html

--
   Richard Huxton
   Archonet Ltd

Re: How can I write trigger on a columns insert/update?

От:
Robert Treat <xzilla@users.sourceforge.net>
Дата:
On Thu, 2005-05-19 at 04:35, Richard Huxton wrote:
> Dinesh Pandey wrote:
> > How can I write trigger on a columns insert/update?
> > 
> > CREATE TRIGGER mytrigger
> > BEFORE
> > INSERT OR UPDATE 
> >           OF mycolumn ON mytable
> 
> You don't I'm afraid. It's not a feature that's supported yet. You have 
> to check which column(s) were changed in your functions.
> 
> It is on the TODO list though:
>    http://www.postgresql.org/docs/faqs.TODO.html
> 

Just to add there is someone working on this for 8.1, hopefully it will
get done. Also the workaround is to create a regular trigger and then do
a check in the function 

IF NEW.mycol <> OLD.mycol THEN... it's not quite as spiff but should do
what you want. 


Robert Treat
-- 
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL

FAQ