RE: [HACKERS] Recursive queries?

From: "Meskes, Michael" <meskes(at)topsystem(dot)de>
To: "Meskes, Michael" <meskes(at)topsystem(dot)de>, "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>
Cc: "'Vadim B(dot) Mikheev'" <vadim(at)sable(dot)krasnoyarsk(dot)su>, PostgreSQL Hacker <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: [HACKERS] Recursive queries?
Date: 1998-02-21 15:27:26
Message-ID: 11720CEF3853D011AC0C00A024B7A9E110A157@EINSTEIN
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Let's say you have a parent relations as (parent, child). Now you want
to compute all ancestors from this relation that is technically spoken
you need a transitive closure.

In logic this looks like:

ancestor(X,Y) :- parent(X,Y).
ancestor(X,Y) :- ancestor(X,Z), parent(Z,Y).

X is ancestor of Y if X is parent of Y or X is ancestor of Z who is
parent of Y.

In POSTQUEL this is written like this (note I'm not sure about correct
POSTQUEL syntax):

retrieve into ancestor(p.x,p.y) from p in parent

retrieve* into ancestor(a.x,p.y) from a in ancestor, p in parent where
a.y=p.x.

You see the second line generates new tuples every time it's executed
until there is no more data deductable.

Michael
--
Dr. Michael Meskes, Projekt-Manager | topystem Systemhaus GmbH
meskes(at)topsystem(dot)de | Europark A2, Adenauerstr. 20
meskes(at)debian(dot)org | 52146 Wuerselen
Go SF49ers! Use Debian GNU/Linux! | Tel: (+49) 2405/4670-44

> ----------
> From: Thomas G. Lockhart[SMTP:lockhart(at)alumni(dot)caltech(dot)edu]
> Sent: Freitag, 20. Februar 1998 17:44
> To: Meskes, Michael
> Cc: 'Vadim B. Mikheev'; PostgreSQL Hacker
> Subject: Re: [HACKERS] Recursive queries?
>
> > But such a statement is executed only once, isn't it?
> >
> > Postquel did execute a retrieve* into as long as it was able to
> generate
> > new data.
>
> OK, I'll bite :)
> Can you give an example of this? How does new data become available in
> the
> middle of a transaction? Just curious...
>

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 1998-02-21 15:29:39 Re: [HACKERS] Backend crashes - what's going on here???
Previous Message Meskes, Michael 1998-02-21 15:27:19 RE: [HACKERS] RE: New ecgp code problem.