5 months, 2 weeks ago Mike Reiche
This comment has the status of 'removed' and can only be seen by you.

How to get the depth of the graph?

<code> WITH RECURSIVE graph as ( SELECT pr.*,@depth as depth FROM rcte_people_relationships pr WHERE source_id=3 UNION SELECT pr.*,(@depth:=@depth+1) as depth FROM rcte_people_relationships pr, graph WHERE graph.target_id=pr.source_id ) SELECT * FROM graph CROSS JOIN (SELECT @depth := 0) AS depth; </code>

Creates an infinite loop.