<div dir="ltr"><div>> Which one is the best example for finding all paths with recursive query?</div><div><br></div><div>What type of graph are you working with?<br></div><div><br></div><div>1.) <br></div>You can check Yugabyte (PostgreSQL compatible) documentation for pure SQL recursive-graph solutions for :<div>- Undirected cyclic graph<br>- Directed cyclic graph<br>- Directed acyclic graph<br>- Rooted tree<br>- Unique containing paths<br><div><a href="https://docs.yugabyte.com/preview/api/ysql/the-sql-language/with-clause/traversing-general-graphs/common-code/">https://docs.yugabyte.com/preview/api/ysql/the-sql-language/with-clause/traversing-general-graphs/common-code/</a><br></div></div><div>I think there's a pretty good summary for solving basic graph problems with SQL, which could potentially help you understand your problem as well and find a solution for it...<br></div><div><br></div><div>2.) </div><div>Or use pgr_KSP - if you're only interested in the final result and you're not attached to the purely recursive SQL solution. <br></div><div>And it's much more optimal for large graphs as well. </div><div>Here, you just need to provide a large enough K value (e.g., ~ maximum (integer/bigint) value) and then you get all possible paths. </div><div>Or if you're only interested in the top 2, then set K=2.<br></div><div><br></div><div><a href="https://docs.pgrouting.org/latest/en/pgr_KSP.html">https://docs.pgrouting.org/latest/en/pgr_KSP.html</a><br></div><div><span style="font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px"><font color="#0000ff">"The K shortest path routing algorithm based on Yen’s algorithm<b style="">. “K” is the number of shortest paths desired.</b>"</font></span><br></div><div><a href="https://en.wikipedia.org/wiki/K_shortest_path_routing">https://en.wikipedia.org/wiki/K_shortest_path_routing</a><br></div><div><br></div><div><span style="color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px">regards,</span></div><div><span style="color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px"> Imre</span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Shaozhong SHI <<a href="mailto:shishaozhong@gmail.com">shishaozhong@gmail.com</a>> ezt írta (időpont: 2023. júl. 17., H, 9:01):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Which one is the best example for finding all paths with recursive query?<div><br></div><div>Regards,</div><div><br></div><div>David</div></div>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><br>
</blockquote></div>