Depth First Reporting - Analytics Database - Teradata Vantage

SQL Data Definition Language Detailed Topics

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2024-12-13
dita:mapPath
vuk1628111288877.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
jbg1472252759029
lifecycle
latest
Product Category
Teradata Vantage™

You can simulate a DFS result by ordering the final result by the path of the recursion. The path in this context means how a row is found through recursive iterations. In this example, the path is the concatenation of the city names.

    CREATE RECURSIVE VIEW reachable_from (destin,cost,depth,path) AS (
      SELECT root.destin, root.cost, 0 AS depth, destin AS path
      FROM flights AS root
      WHERE root.source = 'paris'
    UNION ALL
      SELECT result.destin,seed.cost+result.cost,seed.depth+1 AS depth,
         seed.path||' '||result.destin
      FROM reachable_from AS seed, flights AS result
      WHERE seed.destin = result.source
      AND   depth <= 20);

    SELECT *
    FROM reachable_from
    ORDER BY path;