Breadth 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
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
vuk1628111288877.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1184
lifecycle
latest
Product Category
Teradata Vantage™

You can simulate a BFS result by ordering the final result by the depth of the recursion. For example, consider the following view definition.

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

By ordering the query result on the depth variable, the following SELECT request provides a breadth first report on this view.

    SELECT *
    FROM reachable_from
    ORDER BY depth;