Re: Help with distinctly non-intuitive rule behaviour - Mailing list pgsql-sql

From Tom Lane
Subject Re: Help with distinctly non-intuitive rule behaviour
Date
Msg-id 16903.1141595978@sss.pgh.pa.us
Whole thread Raw
In response to Help with distinctly non-intuitive rule behaviour  ("Simon Kinsella" <simon@bluefiresystems.co.uk>)
List pgsql-sql
"Simon Kinsella" <simon@bluefiresystems.co.uk> writes:
> 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;

This is run before the delete.  However, since it's a conditional rule,
the delete is still run, with the added where-condition
NOT(user_departed > now()).  Since the UPDATE has caused that to be
true, the delete happens.  You should reconsider whether this is to be
conditional or not.
        regards, tom lane


pgsql-sql by date:

Previous
From: "Simon Kinsella"
Date:
Subject: Help with distinctly non-intuitive rule behaviour
Next
From: Greg Stark
Date:
Subject: Re: functions in WHERE clause