标签:ora path geo select 关键字 col 不同 || source
在Oracle数据库中,有可以实现递归的函数
select * from table_name start with [condition1] connect by [condition2]
最近发现Postgresql数据库也有类型递归查询的方法,
与Oracle不同的是,Postgresql没有现成的关键字表示层级和路径,需要自己构造(如下path和depath)
#前提数据必须是树状结构,首尾互联,方向一致(下例中,source和target互联)
WITH RECURSIVE t (gid,source,point,target,path,depath) AS ( SELECT t1.gid,t1.source,ST_StartPoint(t1.geom),t1.target,Array[t1.gid],1 as depath FROM zy t1 WHERE source = ‘8764‘ UNION ALL SELECT t2.gid, t2.source,ST_EndPoint(t2.geom),t2.target,t.path||t2.gid,t.depath+1 as depath FROM zy t2,t WHERE t2.source = t.target ) SELECT * FROM t
标签:ora path geo select 关键字 col 不同 || source
原文地址:https://www.cnblogs.com/giser-s/p/11655649.html