I'm not particularly used to generating complex SQL queries, and it's hard for me to mix my understanding of procedural languages and set-based operations into developing a recursive query to bypass the network. I want to find a set of edges that lie "upstream" of a particular node by conducting a first search for the depth of the oriented graph (each node can have more than one ascending edge) and should ideally implement this in SQL.
The pseudocode for what I want to do is as follows:
interesting_pipes = Pipes[]
func find_all_pipes_upstream(node n)
if is_inlet(nodename)
return Nil
else
for p in upstream_pipes:
if p in interesting_pipes:
return Nil
else
interesting_pipes.append(p)
find_all_pipes_upstream(upstream_node(p))
I have already written the following functions in pure SQL:
upstream_pipes(node_name varchar) RETURNS SETOF "Pipes"
upstream_node(pipe_name varchar) RETURNS "Node"
is_inlet(node_name) RETURNS boolean
,
PostgreSQL WITH RECURSIVE PL/pgSQL. , WITH RECURSIVE, , node . - /, ?
,