Recursive CTE stop condition for loops
I need to iterate a graph with loops using the recursive CTE. The problem is the loop part. I want if there are loops, then the shortest path to be selected. This basically means ignoring the loops because the recursion is "width first". The example below shows the returned data: The problem is the commented out INSERT statement that creates a loop. With it uncommented, obviously, the query will never finish. What I need is to return the same data as it would be without the loop. DROP TABLE IF EXISTS edges; CREATE TABLE edges( src integer, dst integer, data integer ); INSERT INTO edges VALUES