Re: CREATE RULE with WHERE clause

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Ranieri Mazili <ranieri(dot)oliveira(at)terra(dot)com(dot)br>, pgsql-general(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: CREATE RULE with WHERE clause
Date: 2007-06-05 14:07:29
Message-ID: 730028.97435.qm@web31812.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marko Kreen 2007-06-05 14:12:11 Re: Encrypted column
Previous Message Alvaro Herrera 2007-06-05 13:59:51 Re: Encrypted column

Browse pgsql-sql by date

  From Date Subject
Next Message Loredana Curugiu 2007-06-05 14:08:44 Re: [SQL] JOIN
Previous Message Alvaro Herrera 2007-06-05 13:59:51 Re: Encrypted column