Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id C6797476059 for ; Thu, 4 Apr 2002 14:29:31 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g34JTEF25309; Thu, 4 Apr 2002 14:29:14 -0500 (EST) To: Frank Joerdens Cc: pgsql-sql@postgresql.org Subject: Re: Rule trouble (looks to me exactly like the example) In-reply-to: <20020404191719.C30469@superfly.archi-me-des.de> References: <20020404191719.C30469@superfly.archi-me-des.de> Comments: In-reply-to Frank Joerdens message dated "Thu, 04 Apr 2002 19:17:19 +0200" Date: Thu, 04 Apr 2002 14:29:13 -0500 Message-ID: <25306.1017948553@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200204/61 X-Sequence-Number: 7326 Frank Joerdens writes: > And here's the rule (it doesn't do anything real or interesting, I just > simplified it to the point where it looked like the example): > CREATE RULE insert_level AS > ON INSERT TO tree > WHERE new.id > 0 DO > UPDATE tree SET leveling = 1 > WHERE tree.oid = new.oid; What's happening is that "new.id" is effectively still NULL at the point where the rule is processed, so the rule WHERE condition fails. I'm not sure why you're bothering with that WHERE condition anyway ... but this seems to be another argument for moving INSERT's default-value-insertion step to before the rule rewriter. (There was some discussion of this point just a few days ago, IIRC.) regards, tom lane