Skip to content

Instantly share code, notes, and snippets.

@markflorisson
Created February 19, 2016 20:22
Show Gist options
  • Save markflorisson/a0c6b1c71c33836465df to your computer and use it in GitHub Desktop.
Save markflorisson/a0c6b1c71c33836465df to your computer and use it in GitHub Desktop.
create table Edges (n0 INTEGER, n1 INTEGER, label TEXT);
insert into Edges (n0, n1, label) values (0, 1, "e1");
insert into Edges (n0, n1, label) values (1, 2, "e2");
insert into Edges (n0, n1, label) values (1, 3, "e3");
insert into Edges (n0, n1, label) values (2, 4, "e4");
insert into Edges (n0, n1, label) values (3, 5, "e5");
with recursive Traverse(n0, n1)
as ( values(0,0) UNION
select E1.n0, E2.n1
from Traverse E1, Edges E2
where E1.n1 = E2.n0
)
select E.n1 from Traverse E order by E.n1 desc limit 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment