Subject: Re: Trouble with rules

From: postarch (Postgres Mailing Archive)
Date: Mon, 03 Aug 92 16:18:35 PDT

you write:
> 
> Cheers, 
> This is a resend of a query that went off before Easter and may have 
> got lost.   If not - sorry to trouble you again. 
> 
> I am having some problems in using rules.   The first problem concerns 
> a difference between  instance and rewrite rules.  The second is in 
> interpreting the result of a rule.   I would be grateful for advice.
> 
> THE TABLE BEING USED IS FROM THE DEMO DATABASE E.G.
> ==================================================
> * retrieve (emp.all) \g
> 
> Query sent to backend is "retrieve (emp.all) "
> -----------------------------------------------------------------------
> | salary      | manager     | location    | age         | name        |
> -----------------------------------------------------------------------
> | 1000        | sharon      | (11,10)     | 20          | bill        |
> -----------------------------------------------------------------------
> | 1000        | sam         | (15,12)     | 25          | joe         |
> -----------------------------------------------------------------------
> | 80          | bill        | (10,5)      | 30          | sam         |
> -----------------------------------------------------------------------
> 
> THE REWRITE RULE USED IS 
> ========================
> 
>    define rewrite rule q3rule_1 is
>       on append to emp
>    do instead
>       retrieve (e.all)
>         from e in emp 
>         where e.name = new.manager
> 
>  
> I would expect the following APPEND query to act like
>     retrieve (emp.all) where e.name = "x"
> and produce no instances - however I get 2 which seem to fit the query    
>     retrieve (e.all) from e in emp   where e.name = emp.manager
> it seems that 'new' is the whole emp table and not just the instance
> in the APPEND query.
> 
> * append emp(name="a", manager="x")  \g
> 
> Query sent to backend is "append emp(name="a", manager="x")  "
> -----------------------------------------------------------------------
> | salary      | manager     | location    | age         | name        |
> -----------------------------------------------------------------------
> | 1000        | sharon      | (11,10)     | 20          | bill        |
> -----------------------------------------------------------------------
> | 80          | bill        | (10,5)      | 30          | sam         |
> -----------------------------------------------------------------------
> 
> THE FOLLOWING QUERY DOES THE SAME THING.
> 
> * append emp(name="a", manager="sam")  \g
> 

This bug is fixed in the forthcoming 4.0.1 release.  Sorry for the delay.

later,
Adam Glass
postgres research group