Example: Mutual Recursion - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

This example demonstrates mutual recursion, which is not supported for recursive view definitions.

Mutual recursion occurs when both of the following are true:
  • Recursive view A invokes, either directly or indirectly, recursive view B.
  • Recursive view B invokes, either directly or indirectly, recursive view A.

In the two mutually recursive view definitions provided here, the view named odd references the view named even, and the reverse.

    CREATE RECURSIVE VIEW even (n) AS (
      SELECT * 
      FROM (SELECT 0) AS a(i)
    UNION ALL
      SELECT m + 1
      FROM odd);
    CREATE RECURSIVE VIEW odd (m) AS (
      SELECT *
      FROM (SELECT 1) AS a(i)
    UNION ALL
      SELECT n + 1
      FROM even);