Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 3AA0F9FB342 for ; Tue, 5 Jun 2007 11:07:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 05298-04 for ; Tue, 5 Jun 2007 11:07:25 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from web31812.mail.mud.yahoo.com (web31812.mail.mud.yahoo.com [68.142.207.75]) by postgresql.org (Postfix) with SMTP id 59E949FB6BC for ; Tue, 5 Jun 2007 11:07:31 -0300 (ADT) Received: (qmail 7767 invoked by uid 60001); 5 Jun 2007 14:07:29 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=WasIfakzOhOXZ4yNNz4KOjsuap51IO6cnRhTSpgalbGsUjiZIAA6rN+plimf8NdHLqD0+auwX2fvyFS2LJ6x6SfDUT1dH4RQUpr4KOLbviOH5Asck+5WQr9oQ/RyRPGOaZRAXxLcqI2YVzBKiDkDPmmGqGJi3FBJZh06fwRStaw=; X-YMail-OSG: Mc_Rb8QVM1npK1941bwwbuf7ar3EzbfMo3ilnX9.u6ROITf728Fi9zSgJNmoQo7y4FlCm0DI.QtzkoHgi1qnxa55mH.e3b5j0_KtvKE6Qe3097MyDVz9kRwRsppMEg-- Received: from [63.203.180.122] by web31812.mail.mud.yahoo.com via HTTP; Tue, 05 Jun 2007 07:07:29 PDT Date: Tue, 5 Jun 2007 07:07:29 -0700 (PDT) From: Richard Broersma Jr Subject: Re: CREATE RULE with WHERE clause To: Ranieri Mazili , pgsql-general@postgresql.org, pgsql-sql@postgresql.org In-Reply-To: <4665611F.9020500@terra.com.br> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <730028.97435.qm@web31812.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.117 tagged_above=0 required=5 tests=AWL=-1.239, BAYES_50=0.001, DNS_FROM_RFC_ABUSE=0.2, DNS_FROM_RFC_POST=1.708, DNS_FROM_RFC_WHOIS=1.447 X-Spam-Level: ** X-Archive-Number: 200706/396 X-Sequence-Number: 115219 > CREATE RULE rule_role_sul AS > ON SELECT TO t1 WHERE roles = 'role_sul' > DO INSTEAD > SELECT field1, field2 FROM t2; > > CREATE RULE rule_role_sul AS > ON SELECT TO t1 WHERE roles = 'role_norte' > DO INSTEAD > SELECT field3, field4 FROM t2; From: http://www.postgresql.org/docs/8.2/interactive/sql-createrule.html ... WHERE condition Any SQL conditional expression (returning boolean). The condition expression may not refer to any tables except NEW and OLD, and may not contain aggregate functions. ... This statement to me implies that only ON {INSERT | UPDATE | DELETE } actions can use the WHERE syntax since only inserts, updates, and deletes product the NEW.* and OLD.* tables. Also, NEW.* and OLD.* only apply to a single tuple in the view that is being changed. So I do not think you can not use the where syntax in your query since it does not and cannot reference a NEW or OLD tuple. Regards, Richard Broersma Jr.