Re: Rules on select - Mailing list pgsql-general

From Rick Schumeyer
Subject Re: Rules on select
Date
Msg-id 004d01c4fc99$fc6af3c0$0200a8c0@dell8200
Whole thread Raw
In response to Rules on select  (Mariusz Czułada <manieq@idea.net.pl>)
List pgsql-general
As a new user, I recently had the same problem.  I then realized what the
problem is.

You want to select from sharp_p1 instead of selecting from sharp.  That
means you never actually select from sharp.  Since nothing was selected,
postgres can't do anything useful with the WHERE clause.  To put it another
way, how can the db know which rows match the WHERE clause when it never
actually looks at the table?

I hope this helps explain WHY it doesn't work.  Hopefully someone else
can suggest an alternative.


-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Mariusz Czu³ada
Sent: Monday, January 17, 2005 7:29 AM
To: Postgres General
Subject: [GENERAL] Rules on select

Hi,

I tried to create rule on a view. It should contain a WHERE clause.
Unfortunately it does not work:

a_4m=# CREATE RULE sharp_p1_rule AS ON SELECT TO sharp
a_4m-#   WHERE part_key = 1
a_4m-#   DO
a_4m-#   INSTEAD SELECT * FROM sharp_p1;
ERROR:  ON SELECT rule may not use OLD

a_4m=# CREATE RULE sharp_p1_rule AS ON SELECT TO sharp
a_4m-#   WHERE NEW.part_key = 1
a_4m-#   DO
a_4m-#   INSTEAD SELECT * FROM sharp_p1;
ERROR:  relation "*NEW*" does not exist

a_4m=# CREATE RULE sharp_p1_rule AS ON SELECT TO sharp
a_4m-#   WHERE OLD.part_key = 1
a_4m-#   DO
a_4m-#   INSTEAD SELECT * FROM sharp_p1;
ERROR:  ON SELECT rule may not use OLD

Is it my mistake, or some feature I did not find in the docs?

regards,

Mariusz

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html


pgsql-general by date:

Previous
From: Mariusz Czułada
Date:
Subject: Rules on select
Next
From: Nick Burch
Date:
Subject: What is postgresql doing for "statement: commit;begin;"