Subject: Questions on rules

From: [email-masked] (Alfredo Sanchez)
Date: Tue, 27 Jul 93 21:01:43 -0700

Some time ago I asked about the possibility of implementing
some sort of notification mechanism using rules and dynamically
loaded C functions. I just retook that part of my project and
was able to popup a window whenever a "replace" is executed
by the backend. However, I have not been able to make this behavior
more selective. The rule I define is ALWAYS triggered, ignoring the 
"where" clause and the specific attributes indicated by its definition.

I'm using a simple class "Attributes" with attributes "objid", "name",
and  "value" as shown by the following script:

define function popup
(language = "c", returntype = int4, trusted = false)
as "/home/accts/joseash/popup.o"\g

define rewrite rule 
is on replace to Attributes.value where Attributes.name = "status"
do retrieve (x=myquit())\g

* retrieve (Attributes.all) \g

Query sent to backend is "retrieve (Attributes.all) "
-------------------------------------------
| objid       | name        | value       |
-------------------------------------------
| 10          | status      | 30%         |
-------------------------------------------
| 20          | other       | something else|
-------------------------------------------

I would expect the following statement NOT to fire the rule,
but it does:

replace Attributes (name = "whatever") where 
Attributes.value = "something else" \g

Query sent to backend is "replace Attributes (name = "whatever") where Attributes.value = "something else" "
REPLACE---------------
| x           |
---------------
| 0           |
---------------

Am I doing anything wrong?

I would like to have the option to define the rule as instance-level but,
as posted previously, postgres wouldn't let me call my C
function in addition to the "replace" operation. The error message
issued when I do a "define instance rule" is:

WARN:Jun  9 23:38:36:`on retrieve ... do retrieve' tuple rules must 
have an `instead' 

(And I do want to execute the function in addition to replacing)

Is there an explanation for this behavior/semantics?

I will really appreciate any help you can provide.

J Alfredo Sanchez H
-------------------
Hypermedia Research Lab
Texas A&M University