Search Postgresql Archives

Re: The rule question before, request official documentation on the problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In article <461D0B1A.6030407@xxxxxxxxxxxxxxxx>,
Chris Travers <chris@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:

% DO ALSO rules involving NEW are fundamentally dangerous to the integrity 
% of data because NEW is not guaranteed to be internally consistent.  DO 
% INSTEAD rules are fine (there is only one NEW), as are any DO ALSO rules 
% involving OLD.

It seems to me that this sort of dogmatism is fundamentally dangerous.

CREATE TABLE x (a varchar(20) PRIMARY KEY, b INT NOT NULL);
CREATE TABLE y (a varchar(20) NOT NULL, b INT NOT NULL);
CREATE RULE y_ins AS ON INSERT TO y DO UPDATE x SET b=b+new.b WHERE a=new.a;
CREATE RULE y_del AS ON DELETE TO y DO UPDATE x SET b=b-old.b WHERE a=old.a;
INSERT INTO x VALUES ('a', 0);
INSERT INTO y VALUES ('a', 2);
INSERT INTO y VALUES ('a', 2);
SELECT * FROM x;
 a | b 
---+---
 a | 4

DELETE FROM y;
SELECT * FROM x;
 a | b 
---+---
 a | 2

The DO ALSO rules involving OLD didn't do so well here.

The section on rules v. triggers could do with a caveat or two, but
it's a bit much to call them "fundamentally dangerous".
-- 

Patrick TJ McPhee
North York  Canada
ptjm@xxxxxxxxxxxx


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux