Database Reference
In-Depth Information
This fails however, so we need to add two rules, one as an unconditional rule that does
nothing (literally) and needs to exist for internal reasons, and one that does the work we want.
CREATE RULE cust_minor_update_dummy AS
ON update TO cust_minor
DO INSTEAD NOTHING;
CREATE RULE cust_minor_update_conditional AS
ON update TO cust_minor
WHERE new.age < 18
DO INSTEAD
UPDATE cust SET
firstname = new.firstname
,lastname = new.lastname
,age = new.age
WHERE customerid = old.customerid;
There's more...
It should be noted that some, or even perhaps many, DBAs find rules to be a serious
annoyance. Here's one more reason why. Let's try doing our main example a different way
using triggers. We'd like to make this view updateable as follows:
CREATE VIEW cust_view AS
SELECT customerid
,firstname
,lastname
,age
FROM cust;
We can't create triggers on views, so let's try to create a table instead as follows:
CREATE TABLE cust_view AS SELECT * FROM cust WHERE 1 = 0;
 
Search WWH ::




Custom Search