Re: bug (?) with RULEs with WHERE - Mailing list pgsql-hackers

From Tom Lane
Subject Re: bug (?) with RULEs with WHERE
Date
Msg-id 3033.1004205842@sss.pgh.pa.us
Whole thread Raw
In response to bug (?) with RULEs with WHERE  (Kovacs Zoltan <kovacsz@pc10.radnoti-szeged.sulinet.hu>)
Responses Re: bug (?) with RULEs with WHERE
List pgsql-hackers
Kovacs Zoltan <kovacsz@pc10.radnoti-szeged.sulinet.hu> writes:
> foo=# CREATE TABLE a(foo integer);
> CREATE
> foo=# CREATE TABLE b(foo integer);
> CREATE
> foo=# CREATE VIEW c AS SELECT foo FROM a;
> CREATE
> foo=# CREATE RULE d AS ON INSERT TO c WHERE new.foo=5 DO INSTEAD SELECT foo FROM b;
> CREATE
> foo=# INSERT INTO c VALUES (5);
> ERROR:  Cannot insert into a view without an appropriate rule

You didn't provide a rule covering the new.foo<>5 case.

In practice, you *must* have an unconditional INSTEAD rule present for
any view operation you want to allow.  It can be DO INSTEAD NOTHING,
and then you can do all your useful work in conditional rules, but the
unconditional rule must be there.  Else the system thinks that perhaps
the insert into the view would really happen.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: HISTORY file
Next
From: Tom Lane
Date:
Subject: Re: consistent naming of components