Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 53B159FB7E0; Tue, 5 Jun 2007 11:41:20 -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 29664-02; Tue, 5 Jun 2007 11:41:03 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mtao03.charter.net (mtao03.charter.net [209.225.8.188]) by postgresql.org (Postfix) with ESMTP id 271BD9FB923; Tue, 5 Jun 2007 11:41:09 -0300 (ADT) Received: from aa09.charter.net ([10.20.200.161]) by mtao03.charter.net (InterMail vM.7.08.02.00 201-2186-121-20061213) with ESMTP id <20070605144107.BBNU1525.mtao03.charter.net@aa09.charter.net>; Tue, 5 Jun 2007 10:41:07 -0400 Received: from [10.0.1.3] (really [66.188.164.45]) by aa09.charter.net with ESMTP id <20070605144107.FBVK6151.aa09.charter.net@[10.0.1.3]>; Tue, 5 Jun 2007 10:41:07 -0400 In-Reply-To: <4665611F.9020500@terra.com.br> References: <4665611F.9020500@terra.com.br> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <41FB1D71-534B-4358-9B09-A60C35F948B9@seespotcode.net> Cc: pgsql-general@postgresql.org, pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: CREATE RULE with WHERE clause Date: Tue, 5 Jun 2007 09:40:50 -0500 To: Ranieri Mazili X-Mailer: Apple Mail (2.752.2) X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/402 X-Sequence-Number: 115225 On Jun 5, 2007, at 8:11 , Ranieri Mazili wrote: > 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; I don't believe you can include a WHERE clause like this. From the documentation[1]: http://www.postgresql.org/docs/8.2/interactive/rules-views.html#RULES- SELECT > Currently, there can be only one action in an ON SELECT rule, and > it must be an unconditional SELECT action that is INSTEAD. This > restriction was required to make rules safe enough to open them for > ordinary users, and it restricts ON SELECT rules to act like views. You can use views instead (which are implemented using the rule system), but I'm not sure how you would handle it in this case. I believe you'd have to implement two views: CREATE VIEW rule_role_sul AS SELECT field1, field2 FROM t2 WHERE roles = 'role_sul'; CREATE VIEW rule_role_norte AS SELECT field3, field4 FROM t2 WHERE roles = 'role_norte'; Hope this helps. Michael Glaesemann grzm seespotcode net