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

Поиск
Список
Период
Сортировка
От ptjm@interlog.com (Patrick TJ McPhee)
Тема Re: The rule question before, request official documentation on the problem
Дата
Msg-id 131re1ff6rk9k39@corp.supernews.com
обсуждение исходный текст
Ответ на The rule question before, request official documentation on the problem  (Chris Travers <chris@metatrontech.com>)
Список pgsql-general
In article <461D0B1A.6030407@metatrontech.com>,
Chris Travers <chris@verkiel.metatrontech.com> 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@interlog.com

В списке pgsql-general по дате отправления:

Предыдущее
От: Alexey Nalbat
Дата:
Сообщение: deadlock
Следующее
От: Andrew - Supernews
Дата:
Сообщение: Re: hashtext () and collisions