Return-Path: postman 
Delivery-Date: Fri, 17 Sep 93 02:07:52 PDT
Return-Path: postman
Received: by postgres.Berkeley.EDU (5.61/1.29)
	id AA01882; Fri, 17 Sep 93 01:54:00 -0700
Resent-From: postman (POSTGRES mailing list)
Resent-Message-Id: <9309170854.AA01882@postgres.Berkeley.EDU>
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: fernando@afrodita.etsimo.uniovi.es
Received: from polar.etsiig.uniovi.es by postgres.Berkeley.EDU (5.61/1.29)
	id AA01870; Fri, 17 Sep 93 01:53:49 -0700
Received: from afrodita.etsimo.uniovi.es by etsiig.uniovi.es (PMDF V4.2-10
 #4541) id <01H31VYZLUXS8WW5PL@etsiig.uniovi.es>; Fri,
 17 Sep 1993 10:43:51 +0100 (GMT)
Received: by afrodita.etsimo.uniovi.es (5.52/890607.SGI) (for
 postgres@postgres.berkeley.edu) id AA03360; Sat, 17 Jul 93 10:46:47 MDT
Date: Sat, 17 Jul 1993 10:46:44 +0100 (MDT)
From: fernando@afrodita.etsimo.uniovi.es (Fernando Ariznavarreta)
Subject: What's wrong with rules?
To: postgres@postgres.Berkeley.EDU (Postgres Lista de correo.)
Message-Id: <9307170846.AA03360@afrodita.etsimo.uniovi.es>
X-Mailer: ELM [version 2.4 PL20]
Content-Type: text
Content-Transfer-Encoding: 7BIT
Content-Length: 2390
Resent-To: postgres-dist
Resent-Date: Fri, 17 Sep 93 01:53:58 PDT

I'm having problems with rules. I'm trying to use them to simulate a special
king of view.
I'll explain the problem with a simplified example.

First let's create to simple classes.

create A(a= int4)\g
create B(b= int4,aoid= oid)\g

Objetcs in B hold the oid of an object in A in it's aoid field.

let's now create a view of the A objects and their corresponding B objects:

create AB(a= int4, b= int4)\g

define rewrite rule AB_ret
is on retrieve to AB
do instead retrieve (A.a,B.b) where B.aoid= A.oid \g

Let's now try it:

append A(a= 1)\g
append B(b= 1, aoid= A.oid) where A.a= 1 \g
append B(b= 2, aoid= A.oid) where A.a= 1\g

retrieve (AB.all) \g

Postgres answers as expected:
Query sent to backend is "retrieve (AB.all) "
-----------------------------
| a           | b           |
-----------------------------
| 1           | 1           |
-----------------------------
| 1           | 2           |
-----------------------------

Now let's create a rule to make append to B objects using the view:

define rewrite rule AB_a
is on append to AB 
do instead append B(b= current.b,aoid= A.oid) where A.a= current.a \g


Let's try it now:

append AB(b= 3,a= 1)\g

The answer from Postgres is erroneous:
Query sent to backend is "append AB(b= 3,a= 1)"
APPEND 0

If we query the AB view now:
retrieve (AB.all) \g

we get:

Query sent to backend is "retrieve (AB.all) "
-----------------------------
| a           | b           |
-----------------------------
| 1           | 1           |
-----------------------------
| 1           | 2           |
-----------------------------
| 1           | 1           |
-----------------------------
| 1           | 2           |
-----------------------------

Does anybody now what's going on?

If I try to view the rules by making the query:

retrieve (pg_rewrite.all)\g

The backend unexpectedly hangs and never returns.

I tried this using 'define view' with similar results.

I am using a port of Postgres v 4.01 to hpux.
Is this a problem with this release or with the port?

Thanks in advance.

-- 
Fernando Ariznavarreta Fernandez       E-Mail:fernando@etsimo.uniovi.es
Dpto. Explotacion y Prospeccion de Minas     Phone: +34 8 510 4267
School of Mines. University of Oviedo               +34 8 510 4336
Independencia, 13                            Fax:   +34 8 510 4242
Oviedo 33004, SPAIN                                 +34 8 510 4340

