Re: Using SETOF functions in SQL

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Pavel Velikhov <pvelikhov(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Using SETOF functions in SQL
Date: 2006-08-15 16:06:15
Message-ID: 1155657975.11726.79.camel@dogma.v10.wvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2006-08-15 at 12:38 +0100, Pavel Velikhov wrote:
> SELECT t1.node, t2.node, path FROM t1,t2, connections(t1.id, t2.id) as
> path
>
> I get the notorious: ERROR: subquery in FROM may not refer to other
> relations of same query level
>

The FROM list must be a list of relations, but in that situation,
connections() creates a different relation for each relation in the join
of t1 and t2. You certainly don't want to join a variable number of
relations together (nor is that allowed).

You could make connections() return the entire set of all connections
and join based on t1.id and t2.id.

Another way to do it would be to do something like "SELECT t1.node,
t2.node, get_path(t1.node,t2.node) from t1, t2 where get_path
(t1.node,t2.node) is not null". Then just make get_path() return null if
the nodes aren't connected.

Regards,
Jeff Davis

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Harpreet Dhaliwal 2006-08-15 16:11:36 Re: Connection string
Previous Message Max 2006-08-15 16:05:36