Re: Fwd: Trigger on VIEW not firing

From: Massimo Costantini <massimo(dot)costantini(at)gmail(dot)com>
To: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
Cc: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Fwd: Trigger on VIEW not firing
Date: 2013-07-30 13:01:26
Message-ID: CAO_q5tuw10SewZjtJ+gxxLUhRWqPyCQN0i9PyrQvO8D9Pv9Giw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgeu-general pgsql-general

Thisi is my real situation, can I do this:

CREATE TABLE alarm(
name text,
id integer,
type text,
init timestamp,
fired timestamp,
end timestamp,
user test
);

CREATE TABLE car (
id integer,
type text,
speed double
);

CREATE VIEW speedv AS SELECT * FROM car WHERE speed>100;

CREATE OR REPLACE FUNCTION update_alarm_view() RETURNS TRIGGER AS $alarm_tg$
BEGIN
IF (TG_OP = 'UPDATE') THEN
INSERT INTO alarm VALUES(NEW.type,
0,'SPEED',now(),NULL,NULL,'');
RETURN NEW;
ELSEIF (TG_OP = 'INSERT') THEN
INSERT INTO alarm VALUES(NEW.type,
0,'SPEED',now(),NULL,NULL,'');
RETURN NEW;
END IF;
END;
$alarm_tg$ LANGUAGE plpgsql;

CREATE TRIGGER alarm_tg INSTEAD OF INSERT OR DELETE OR UPDATE ON speedv
FOR EACH ROW EXECUTE PROCEDURE update_alarm_view();

On Tue, Jul 30, 2013 at 2:49 PM, Ian Lawrence Barwick <barwick(at)gmail(dot)com>wrote:

> 2013/7/30 Massimo Costantini <massimo(dot)costantini(at)gmail(dot)com>:
> >
> > Hi,
> >
> > I have a problem with Triggers on VIEW:
> >
> > suppose I have:
> >
> > CREATE TABLE work (
> > id integer NOT NULL,
> > work TEXT,
> > worktype TEXT
> > );
> >
> > CREATE VIEW worksub AS SELECT FROM work WHERE worktype='subordinate';
> >
> >
> > CREATE OR REPLACE FUNCTION wrk_view() RETURNS TRIGGER AS $wrk_tg$
> > BEGIN
> > RAISE NOTICE 'UPDATE VIEW FROM: % OPERATION: %',TG_TABLE_NAME,
> > TG_OP;
> > END;
> > $wrk_tg$ LANGUAGE plpgsql;
> >
> > CREATE TRIGGER wrk_tg INSTEAD OF INSERT OR DELETE OR UPDATE ON worksub
> > FOR EACH ROW EXECUTE PROCEDURE wrk_view();
> >
> > nothing appen when I insert row in work table.
>
> The trigger is on the view "worksub", not the "work" table.
>
> BTW the trigger function doesn't return anything, which will cause an
> error.
> (Also the view definition is missing column definitions in the SELECT
> clause).
>
> Regards
>
> Ian Barwick
>

In response to

Responses

Browse pgeu-general by date

  From Date Subject
Next Message Ashutosh Durugkar 2013-07-30 13:04:46 Re: Trigger on VIEW not firing
Previous Message Beena Emerson 2013-07-30 12:55:40 Re: Fwd: Trigger on VIEW not firing

Browse pgsql-general by date

  From Date Subject
Next Message Ashutosh Durugkar 2013-07-30 13:04:46 Re: Trigger on VIEW not firing
Previous Message Beena Emerson 2013-07-30 12:55:40 Re: Fwd: Trigger on VIEW not firing