Services
24×7×365 Technical Support
Migration to PostgreSQL
High Availability Deployment
Database Audit
Remote DBA for PostgreSQL
Products
Postgres Pro Enterprise
Postgres Pro Standard
Cloud Solutions
Postgres Extensions
Resources
Blog
Documentation
Webinars
Videos
Presentations
Community
Events
Training Courses
Books
Demo Database
Mailing List Archives
About
Leadership team
Partners
Customers
In the News
Press Releases
Press Info
Services
24×7×365 Technical Support
Migration to PostgreSQL
High Availability Deployment
Database Audit
Remote DBA for PostgreSQL
Products
Postgres Pro Enterprise
Postgres Pro Standard
Cloud Solutions
Postgres Extensions
Resources
Blog
Documentation
Webinars
Videos
Presentations
Community
Events
Training Courses
Books
Demo Database
Mailing List Archives
About
Leadership team
Partners
Customers
In the News
Press Releases
Press Info
Facebook
Downloads
Home
>
mailing lists
Re: Fwd: Trigger on VIEW not firing - Mailing list pgsql-general
From
Beena Emerson
Subject
Re: Fwd: Trigger on VIEW not firing
Date
July 30, 2013
16:30:51
Msg-id
CAOG9ApGOsziKO0ncBYUY5h2443D=MgbqJV4Z1ZsEX+2+NskhUA@mail.gmail.com
Whole thread
Raw
In response to
Re: Fwd: Trigger on VIEW not firing
(Massimo Costantini <massimo.costantini@gmail.com>)
Responses
Re: Fwd: Trigger on VIEW not firing
List
pgsql-general
Tree view
Hi again,
IIUC you want to update the alarm table only when the speed limit is above 100. You cannot achieve it by the view and triggers you have written here because the trigger will be fired even for values < 100
=# INSERT INTO speedv VALUES (1, 'test', 10);
INSERT 0 1
=# SELECT * FROM speedv;
id | type | speed
----+------+-------
(0 rows)
=# SELECT * FROM car;
id | type | speed
----+------+-------
(0 rows)
=# SELECT * FROM alarm;
name | id | type | init | fired | t_end | t_user
------+----+-------+----------------------------+-------+-------+--------
test | 0 | SPEED | 2013-07-30 18:08:01.006979 | | |
test | 0 | SPEED | 2013-07-30 18:20:00.73507 | | |
(2 rows)
If you want to update the alarm table for speed > 100 then use an if else clause in the trigger function:
CREATE OR REPLACE FUNCTION update_alarm_view() RETURNS TRIGGER AS $alarm_tg$
BEGIN
IF (new.speed > 100) THEN
IF (TG_OP = 'UPDATE') THEN
INSERT INTO alarm VALUES(NEW.type, 0,'SPEED',now(),NULL,NULL,'');
ELSEIF (TG_OP = 'INSERT') THEN
INSERT INTO alarm VALUES(NEW.type, 0,'SPEED',now(),NULL,NULL,'');
END IF;
END IF;
RETURN new;
END;
$alarm_tg$ LANGUAGE plpgsql;
And write the trigger on the car table.
--
Beena Emerson
pgsql-general
by date:
Previous
From:
Beena Emerson
Date:
30 July 2013, 16:11:11
Subject:
Re: Fwd: Trigger on VIEW not firing
Next
From:
Massimo Costantini
Date:
30 July 2013, 16:55:06
Subject:
Re: Fwd: Trigger on VIEW not firing
Есть вопросы? Напишите нам!
Соглашаюсь с условиями обработки персональных данных
I confirm that I have read and accepted PostgresPro’s
Privacy Policy
.
I agree to get Postgres Pro discount offers and other marketing communications.
✖
×
×
Everywhere
Documentation
Mailing list
List:
all lists
pgsql-general
pgsql-hackers
buildfarm-members
pgadmin-hackers
pgadmin-support
pgsql-admin
pgsql-advocacy
pgsql-announce
pgsql-benchmarks
pgsql-bugs
pgsql-chat
pgsql-cluster-hackers
pgsql-committers
pgsql-cygwin
pgsql-docs
pgsql-hackers-pitr
pgsql-hackers-win32
pgsql-interfaces
pgsql-jdbc
pgsql-jobs
pgsql-novice
pgsql-odbc
pgsql-patches
pgsql-performance
pgsql-php
pgsql-pkg-debian
pgsql-pkg-yum
pgsql-ports
pgsql-rrreviewers
pgsql-ru-general
pgsql-sql
pgsql-students
pgsql-testers
pgsql-translators
pgsql-www
psycopg
Period
anytime
within last day
within last week
within last month
within last 6 months
within last year
Sort by
date
reverse date
rank
Services
24×7×365 Technical Support
Migration to PostgreSQL
High Availability Deployment
Database Audit
Remote DBA for PostgreSQL
Products
Postgres Pro Enterprise
Postgres Pro Standard
Cloud Solutions
Postgres Extensions
Resources
Blog
Documentation
Webinars
Videos
Presentations
Community
Events
Training Courses
Books
Demo Database
Mailing List Archives
About
Leadership team
Partners
Customers
In the News
Press Releases
Press Info
By continuing to browse this website, you agree to the use of cookies. Go to
Privacy Policy
.
I accept cookies