Return-Path: pg_adm@postgres.berkeley.edu
Received: by postgres.Berkeley.EDU (5.61/1.29)
	id AA08201; Sat, 21 Nov 92 06:59:03 -0800
Message-Id: <9211211459.AA08201@postgres.Berkeley.EDU>
From: Soren Larsen <larsen@imada.ou.dk>
Subject: Foreign keys and the rule system
To: postgres@postgres.berkeley.edu
Sender: pg_adm@postgres.berkeley.edu
To: postgres@postgres.Berkeley.EDU
Date: Sat, 21 Nov 92 15:59:22 GMT
X-Mailer: ELM [version 2.3 PL11]

We have created two classes X and Y by

	create X(k=int2, a=char16)
	create Y(p=int2, q=int2)

where k and p are primary keys.  Furthermore, we want q to act as a
foreign key, such that tuples may not be added to Y unless an X object
exists with X.k=Y.q.
Question: can this integrity constraint be enforced using the rule
system?  We have tried:

define rewrite rule FK is on append to Y
	where count{X.k where X.k=new.q} = 0
	do instead nothing

but we are told that there is a syntax error at or near "{".
Is there another way?

-- 
Soren Larsen / larsen@imada.ou.dk
Dept. of Math. & Computer Science, Odense University
Campusvej 55, DK-5230 Odense M, Denmark
phone: +45 66 15 86 00, ext. 2312 / telefax: +45 65 93 26 91
