Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?] Recurrent CTE results are wrong (2) #496

Closed
hiroyuki0415 opened this issue Jun 21, 2024 · 0 comments · Fixed by #497
Closed

[Bug?] Recurrent CTE results are wrong (2) #496

hiroyuki0415 opened this issue Jun 21, 2024 · 0 comments · Fixed by #497

Comments

@hiroyuki0415
Copy link

The following is a recursive CTE that recursively retrieves the parent (3 layers) of [businessunit]:

WITH     cte
AS       (SELECT NULL AS [child],
                 e0.logicalname AS [parent],
                 e0.logicalname AS [path],
                 0 AS [depth]
          FROM   metadata.entity AS e0
          WHERE  e0.logicalname IN ('businessunit')
          UNION ALL
          SELECT rs.referencingentity AS [child], --(※1)
                 --cte.parent AS [child], (※2)
                 rs.referencedentity AS [parent],
                 cte.path + '/' + rs.referencedentity AS [path],
                 cte.depth + 1 AS [depth]
          FROM   cte AS cte
                 INNER JOIN
                 metadata.relationship_n_1 AS rs
                 ON cte.parent = rs.referencingentity
          WHERE  cte.depth < 3)
SELECT   *
FROM     cte
ORDER BY depth;
  1. All [child] columns have the same value. This is clearly wrong.
    • actual
      actual
    • expected
      expected
  2. When I used (*2) instead of (*1), the result changed. This is also strange.
    actual2
@MarkMpn MarkMpn mentioned this issue Jun 21, 2024
@MarkMpn MarkMpn linked a pull request Jun 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant