Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5PI1Va58944 for ; Mon, 25 Jun 2001 14:01:31 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) 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 f5PI1B316746; Mon, 25 Jun 2001 14:01:16 -0400 (EDT) To: Luis Sousa cc: pgsql sql Mailing List Subject: Re: Problems using a rule with the WHERE clause In-reply-to: <3B3753FB.2E1BA9B0@ualg.pt> References: <3B3753FB.2E1BA9B0@ualg.pt> Comments: In-reply-to Luis Sousa message dated "Mon, 25 Jun 2001 16:08:44 +0100" Date: Mon, 25 Jun 2001 14:01:11 -0400 Message-ID: <16743.993492071@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200106/404 X-Sequence-Number: 3701 Luis Sousa writes: > CREATE RULE "updateturnodocente" AS ON UPDATE TO "docentesturno" > WHERE OLD.idpessoal != 0 > DO INSTEAD ( > ... > When I execute the INSERT into de view docentesturno I got the message: > ERROR: Cannot update a view without an appropriate rule You failed to supply a rule covering the case OLD.idpessoal = 0. More specifically, you *must* supply an unconditional INSTEAD rule to replace the attempt to insert/update in the view. Possibly what you want is CREATE RULE "updateturnodocente" AS ON UPDATE TO "docentesturno" WHERE OLD.idpessoal != 0 DO ( ... ); CREATE RULE "updateturnodocente_default" AS ON UPDATE TO "docentesturno" DO INSTEAD NOTHING; Here, the unconditional rule always fires, and the conditional one fires only when its condition is true. regards, tom lane