Re: Help with distinctly non-intuitive rule behaviour

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Simon Kinsella" <simon(at)bluefiresystems(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Help with distinctly non-intuitive rule behaviour
Date: 2006-03-05 21:59:38
Message-ID: 16903.1141595978@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Simon Kinsella" <simon(at)bluefiresystems(dot)co(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Greg Stark 2006-03-05 22:22:38 Re: functions in WHERE clause
Previous Message Simon Kinsella 2006-03-05 21:18:12 Help with distinctly non-intuitive rule behaviour