On 20/12/2017 22:31, Shane Dev wrote:
Is there a query which can detect all cycles regardless of length?

Not.. cough... particularly efficient, but simple:

with recursive Paths(s,t) as (
  select parent, child from Edges
  union
  select parent, t from Edges join Paths on child = s
)
select count(*) > 0 from Paths where s = t;

This finds all pairs of nodes reachable from each other,
then checks whether there are nodes reachable from themselves.
It returns 1 if there are cycles, 0 otherwise.

A better way would probably be to write a function that performs a
dfs.

Life.

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to