pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Simon Kinsella <simon@bluefiresystems.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: Help with distinctly non-intuitive rule behaviour
Date: Sun, 05 Mar 2006 16:59:38 -0500
Message-ID: <16903.1141595978@sss.pgh.pa.us> (raw)
In-Reply-To: <20060305211817.2DBF3199CFD@smtp04l.fasthosts.co.uk>
References: <20060305211817.2DBF3199CFD@smtp04l.fasthosts.co.uk>

"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



view thread (2+ messages)

Message-ID: <16903.1141595978@sss.pgh.pa.us>
Permalink:  ../16903.1141595978@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16903.1141595978@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, simon@bluefiresystems.co.uk
  Subject: Re: Help with distinctly non-intuitive rule behaviour
  In-Reply-To: <16903.1141595978@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox