Return-Path: owner-postman
Received: from localhost (localhost [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id GAA00605 for postgres-dist; Thu, 11 Nov 1993 06:37:45 -0800
Resent-From: POSTGRES mailing list <postman@postgres.Berkeley.EDU>
Resent-Message-Id: <199311111437.GAA00605@nobozo.CS.Berkeley.EDU>
X-Authentication-Warning: nobozo.CS.Berkeley.EDU: Host localhost didn't use HELO protocol
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: owner-postman
Received: from fel.tno.nl (tnofel.fel.tno.nl [192.55.105.65]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id GAA00596 for <postgres@nobozo.CS.Berkeley.EDU>; Thu, 11 Nov 1993 06:37:39 -0800
Received: by fel.tno.nl id AA12842
  (5.65c/IDA-1.4.3 for postgres@postgres.berkeley.edu); Thu, 11 Nov 1993 15:38:44 +0100
From: Peter van Oosterom <P.v.Oosterom@fel.tno.nl>
Message-Id: <199311111438.AA12842@fel.tno.nl>
Subject: rewrite rule
To: postgres@postgres.Berkeley.EDU
Date: Thu, 11 Nov 93 15:38:44 MET
X-Mailer: ELM [version 2.3 PL11]
Resent-To: postgres-dist@postgres.Berkeley.EDU
Resent-Date: Thu, 11 Nov 93 06:37:41 -0800
Resent-XMts: smtp

Dear Postgres-group,

There seams to be an error in the "rewrite rule" system.
Consider the following example; create, fill, and inspect a relation:
  create rel(a=text, b=int4)\g
  append rel(a="AAB", b=10)\g
  append rel(a="HLP", b=3)\g
  retrieve (rel.all)\g
This gives:
  -----------------------------
  | a           | b           |
  -----------------------------
  | HLP         | 3           |
  -----------------------------
  | AAB         | 10          |
  -----------------------------
Now define a rule to change "AAB" into "Y" and inspect the relation again:
  define rewrite rule r1 is
    on retrieve to rel.a where current.a = "AAB"
    do instead retrieve (a = "Y")\g
  retrieve (rel.all)\g
This gives:
  -----------------------------
  | a           | b           |
  -----------------------------
  | Y           | 3           |
  -----------------------------
  | Y           | 10          |
  -----------------------------
Note that "HLP" is also changed into "Y", which should not be the case.
More testing reveals that every string is converted to "Y".
However, using an "instance rule" instead of a "rewrite rule" works fine:
  remove rewrite rule r1\g
  define instance rule r2 is
    on retrieve to rel.a where current.a = "AAB"
    do instead retrieve (a = "Y")\g
  retrieve (rel.all)\g
This gives:
  -----------------------------
  | a           | b           |
  -----------------------------
  | HLP         | 3           |
  -----------------------------
  | Y           | 10          |
  -----------------------------
This is the right result.
Can somebody tell me what is wrong with the rewrite rule (or perhaps
what did I do wrong with the rewrite rule)?

Kind regards, Peter van Oosterom (oosterom@fel.tno.nl)
