X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 131C59DCE16 for ; Sun, 5 Mar 2006 17:59:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21008-10 for ; Sun, 5 Mar 2006 17:59:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 891689DCE05 for ; Sun, 5 Mar 2006 17:59:37 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k25LxcsP016904; Sun, 5 Mar 2006 16:59:38 -0500 (EST) To: "Simon Kinsella" cc: pgsql-sql@postgresql.org Subject: Re: Help with distinctly non-intuitive rule behaviour In-reply-to: <20060305211817.2DBF3199CFD@smtp04l.fasthosts.co.uk> References: <20060305211817.2DBF3199CFD@smtp04l.fasthosts.co.uk> Comments: In-reply-to "Simon Kinsella" message dated "Sun, 05 Mar 2006 21:18:12 +0000" Date: Sun, 05 Mar 2006 16:59:38 -0500 Message-ID: <16903.1141595978@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.112 required=5 tests=[AWL=0.112] X-Spam-Score: 0.112 X-Spam-Level: X-Archive-Number: 200603/105 X-Sequence-Number: 24451 "Simon Kinsella" 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