Last active
November 11, 2015 21:14
Revisions
-
adunstan revised this gist
Nov 11, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,3 +14,6 @@ dag (depended_on,dependent) as -- c1 a1 d4 d3 d2 d1 b2 with b1 anywhere after a1 ) --- continue here ... -- solution from RhodiumToad with recursive r(item,path) as (select dependent, array[]::text[] from dag d1 where not exists (select 1 from dag d2 where d2.depended_on=d1.dependent) union all select depended_on, path || dependent from dag join r on (r.item=dag.dependent)) select * from (select distinct on (item) item,path from r order by item, cardinality(path) desc) s order by cardinality(path); -
adunstan revised this gist
Nov 11, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ with recursive dag (depended_on,dependent) as ( values ('b2'::text,'d1'::text), -
adunstan revised this gist
Nov 11, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,4 +13,4 @@ vals (depended_on,dependent) as -- expected order is: -- c1 a1 d4 d3 d2 d1 b2 with b1 anywhere after a1 ) --- continue here ... -
adunstan created this gist
Nov 11, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ with recursive vals (depended_on,dependent) as ( values ('b2'::text,'d1'::text), ('d1','d2'), ('d2','d3'), ('d3','d4'), ('b1','a1'), ('b2','a1'), ('a1','c1'), ('d4','a1') -- expected order is: -- c1 a1 d4 d3 d2 d1 b2 with b1 anywhere after a1 ) --- contrinue here ...