Re: [GENERAL] CREATE RULE with WHERE clause - Mailing list pgsql-sql

From Richard Broersma Jr
Subject Re: [GENERAL] CREATE RULE with WHERE clause
Date
Msg-id 730028.97435.qm@web31812.mail.mud.yahoo.com
Whole thread Raw
In response to CREATE RULE with WHERE clause  (Ranieri Mazili <ranieri.oliveira@terra.com.br>)
List pgsql-sql
> CREATE RULE rule_role_sul AS
>     ON SELECT TO t1 WHERE roles = 'role_sul'
>     DO INSTEAD
>         SELECT field1, field2 FROM t2;
>
> CREATE RULE rule_role_sul AS
>     ON SELECT TO t1 WHERE roles = 'role_norte'
>     DO INSTEAD
>         SELECT field3, field4 FROM t2;

From: http://www.postgresql.org/docs/8.2/interactive/sql-createrule.html
...
WHERE condition
Any SQL conditional expression (returning boolean). The condition expression may not refer to any
tables except NEW and OLD, and may not contain aggregate functions.
...

This statement to me implies that only ON {INSERT | UPDATE | DELETE } actions can use the WHERE
syntax since only inserts, updates, and deletes product the NEW.* and OLD.* tables.

Also, NEW.* and OLD.* only apply to a single tuple in the view that is being changed.  So I do not
think you can not use the where syntax in your query since it does not and cannot reference a NEW
or OLD tuple.

Regards,
Richard Broersma Jr.

pgsql-sql by date:

Previous
From: Sean Davis
Date:
Subject: Re: [NOVICE] JOIN
Next
From: "Loredana Curugiu"
Date:
Subject: Re: JOIN