Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-26985

Outside reference in recursive common table expression

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      Since lack of TABLE() function, I try to use recursive CTE to emulate same functionality:

      SELECT * FROM 
      (SELECT 5 mx) a0,
      (
      WITH recursive r as
      (SELECT 1 level 
      union all
      select LEVEL+1 FROM r where LEVEL+1<=5 -- a0.mx
      )
      select level FROM r
      )
      

      This works fine. But I'm interested in uncommented version:

      SELECT * FROM 
      (SELECT 5 mx) a0,
      (
      WITH recursive r as
      (SELECT 1 level 
      union all
      select LEVEL+1 FROM r where LEVEL+1<=a0.mx
      )
      select level FROM r
      )
      

      or

      WITH a0 as
      (SELECT 5 mx)
      SELECT * FROM ( 
      WITH recursive r as
      (SELECT 1 level 
      union all
      select LEVEL+1 FROM r,a0 where LEVEL+1<=a0.mx
      )
      select level FROM r
      )
      

      to use value from outside inline view. Unfortunately both queries fail with error. Can you provide a sample query to demonstrate how can I use value from outside inline view that could be used in recursive loop exit condition?

      Attachments

        Activity

          People

            Unassigned Unassigned
            balta Tadas Balaišis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.