Skip site navigation (1) Skip section navigation (2)

Re: bug (?) with RULEs with WHERE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kovacs Zoltan <kovacsz(at)pc10(dot)radnoti-szeged(dot)sulinet(dot)hu>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: bug (?) with RULEs with WHERE
Date: 2001-10-27 18:04:02
Message-ID: 3033.1004205842@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackers
Kovacs Zoltan <kovacsz(at)pc10(dot)radnoti-szeged(dot)sulinet(dot)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

In response to

Responses

pgsql-hackers by date

Next:From: Stephan SzaboDate: 2001-10-27 18:56:31
Subject: Re: HISTORY file
Previous:From: Peter EisentrautDate: 2001-10-27 17:44:05
Subject: HISTORY file

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group