Help with distinctly non-intuitive rule behaviour
От | Simon Kinsella |
---|---|
Тема | Help with distinctly non-intuitive rule behaviour |
Дата | |
Msg-id | 20060305211817.2DBF3199CFD@smtp04l.fasthosts.co.uk обсуждение исходный текст |
Ответы |
Re: Help with distinctly non-intuitive rule behaviour
|
Список | pgsql-sql |
Hello, Can this possibly be right? From my troubleshooting of a DELETE rule it appears that the rule's WHERE condition sees the *results* of the rule-actions. Apart from being pretty odd, this is a proving to be a big problem in my situation. Here is a cut-down example: Given a table 'users', let's say we would like to 'soft-delete' users from the table by rewriting DELETE as UPDATE using the rule below. For active users the users.user_departed field is 'infinity'::TIMESTAMP. The UPDATE action sets the timestamp of the user's deletion, if and only if the current timestamp is in the future: CREATE RULE rule_soft_delete_user AS ON DELETE TO users WHERE user_departed > now() DO INSTEAD UPDATE users SET user_departed= now() WHERE user_id = OLD.user_id; However, this does not work. I know this because I get a foreign-key violation resulting from an unmolested DELETE action even for a user who has not been soft-deleted. If as a test I change the UPDATE action so that it does something other than change the timestamp then the rule is applied. This seems pretty weird - can it be true? --- Simon Kinsella This message has been scanned for viruses.
В списке pgsql-sql по дате отправления: