pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Luis Sousa <llsousa@ualg.pt>
Cc: pgsql sql Mailing List <pgsql-sql@postgresql.org>
Subject: Re: Problems using a rule with the WHERE clause
Date: Mon, 25 Jun 2001 14:01:11 -0400
Message-ID: <16743.993492071@sss.pgh.pa.us> (raw)
In-Reply-To: <3B3753FB.2E1BA9B0@ualg.pt>
References: <3B3753FB.2E1BA9B0@ualg.pt>

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



view thread (6+ messages)  latest in thread

Message-ID: <16743.993492071@sss.pgh.pa.us>
Permalink:  ../16743.993492071@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16743.993492071@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, llsousa@ualg.pt
  Subject: Re: Problems using a rule with the WHERE clause
  In-Reply-To: <16743.993492071@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox