RE: [HACKERS] Recursive queries? - Mailing list pgsql-hackers

From Meskes, Michael
Subject RE: [HACKERS] Recursive queries?
Date
Msg-id 11720CEF3853D011AC0C00A024B7A9E110A157@EINSTEIN
Whole thread Raw
List 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@topsystem.de                    | Europark A2, Adenauerstr. 20
meskes@debian.org                      | 52146 Wuerselen
Go SF49ers! Use Debian GNU/Linux!      | Tel: (+49) 2405/4670-44

> ----------
> From:     Thomas G. Lockhart[SMTP:lockhart@alumni.caltech.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...
>

pgsql-hackers by date:

Previous
From: "Meskes, Michael"
Date:
Subject: RE: [HACKERS] RE: New ecgp code problem.
Next
From: "Thomas A. Szybist"
Date:
Subject: Re: [PORTS] Sparc/Linux oddity...