aschuma

POSTGRES :: JIRA :: Issuelink Hierarchy

Aug 13th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.93 KB | None | 0 0
  1. -- POSTGRES
  2.  
  3. -- Berechnung aller Pfade zu Kind-Issues modelliert via Issue-Links inklusive Zykle-Erkennung.
  4. -- 10000 : id des Vater Kind Links
  5. -- 11371 : id des Projektes/aktueller Monatsabschuss
  6.  
  7. WITH RECURSIVE
  8. hissuelink(id,SOURCE,destination) AS (SELECT id,SOURCE,destination FROM issuelink WHERE linktype = 10000),
  9. hierarchy( hlevel, hdest, hpatharray, cycle ) AS (
  10.   SELECT 0, id, ARRAY[(CAST(id AS VARCHAR))], FALSE FROM  jiraissue i  WHERE project = 11371 AND i.id NOT IN (SELECT destination FROM hissuelink)  
  11.   UNION ALL (
  12.           SELECT hlevel + 1, destination, hpatharray || (CAST(destination AS VARCHAR)), (CAST(destination AS VARCHAR)) = ANY(hpatharray)
  13.           FROM hissuelink link, hierarchy h
  14.           WHERE link.SOURCE = hdest AND NOT cycle
  15.   )
  16. )
  17.  
  18. SELECT * FROM hierarchy ORDER BY hlevel;
  19.  
  20. -- Literatur:
  21. -- * IX 1/2013 SQL-Know-how (Oracle)
  22. -- * http://www.postgresql.org/docs/9.1/static/queries-with.html
Advertisement
Add Comment
Please, Sign In to add comment