Re: Problems using a rule with the WHERE clause - Mailing list pgsql-sql

From Tom Lane
Subject Re: Problems using a rule with the WHERE clause
Date
Msg-id 16743.993492071@sss.pgh.pa.us
Whole thread Raw
In response to Problems using a rule with the WHERE clause  (Luis Sousa <llsousa@ualg.pt>)
List pgsql-sql
Luis Sousa <llsousa@ualg.pt> 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


pgsql-sql by date:

Previous
From: Wei Weng
Date:
Subject: control structure in a transaction block?
Next
From: "William Herring"
Date:
Subject: select with multiple occurences in same table