Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
smpa01
Super User
Super User

Recursion Strategy

How can I perform recursive queries currently?

I am getting Recursive CTEs are unsupported in this version of Synapse SQL.

 

Is Recursion on cards?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
2 ACCEPTED SOLUTIONS
AndyDDC
Most Valuable Professional
Most Valuable Professional

Hi   at the moment there is no support for recursion in CTEs in the roadmap.  This was something that was requested in Synapse Serverless (which the lakehouse sql endpoint and warehouse is based on) but never happened.  What's new and planned for Synapse Data Warehouse in Microsoft Fabric - Microsoft Fabric | Microsoft...

 

In terms of what you can do for recursion, I write a query in which I join the same table back on itself.  E.G here's an example of basic recursion in an employees table.  This example can be used in the Warehouse, but can also be used in the lakehouse sql endpoint if the tables existed (eg created by spark).

 

create table employees
(
    empid int,
    empname varchar(50),
    managerid int
);

insert into employees
values (1,'andy',null),(2,'dave',1),(3,'alice',1),(4,'glenda',3)

select
    a.empname as EmployeeName,
    b.empname as ManagerName
from employees a
left join employees b on b.empid = a.managerid 

---------------------------------------------------------------

If my reply has been useful please consider providing kudos

and marking as the solution to help others users

---------------------------------------------------------------

View solution in original post

AndyDDC
Most Valuable Professional
Most Valuable Professional

The reason recursion is supported in Datamart is that its backended by Azure SQL Database while the Lakehouse SQL Endpoint and Warehouse are a new MPP engine (started with Synapse Serverless).  With Fabric, MS have built a SQL engine from scratch with fundamentally different architecture to SQL Server/Azure SQL Database so not everything we expect will be there right now, if at all.

View solution in original post

4 REPLIES 4
AndyDDC
Most Valuable Professional
Most Valuable Professional

Hi   at the moment there is no support for recursion in CTEs in the roadmap.  This was something that was requested in Synapse Serverless (which the lakehouse sql endpoint and warehouse is based on) but never happened.  What's new and planned for Synapse Data Warehouse in Microsoft Fabric - Microsoft Fabric | Microsoft...

 

In terms of what you can do for recursion, I write a query in which I join the same table back on itself.  E.G here's an example of basic recursion in an employees table.  This example can be used in the Warehouse, but can also be used in the lakehouse sql endpoint if the tables existed (eg created by spark).

 

create table employees
(
    empid int,
    empname varchar(50),
    managerid int
);

insert into employees
values (1,'andy',null),(2,'dave',1),(3,'alice',1),(4,'glenda',3)

select
    a.empname as EmployeeName,
    b.empname as ManagerName
from employees a
left join employees b on b.empid = a.managerid 

---------------------------------------------------------------

If my reply has been useful please consider providing kudos

and marking as the solution to help others users

---------------------------------------------------------------

I don't think it is easy to come up with an alternative of conventional cte recursion for all scenarios. There are situations which needs both recursive ctes and cursors. The funny part is cte recursion is supported in datamart but not in Fabric artifacts.

 

I am yet to test if cursor is supported.

 

TBH they are integral part of data engineering and MS must consider adding support for them in the Fabric elemnets that have sql endpoints.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
AndyDDC
Most Valuable Professional
Most Valuable Professional

AndyDDC
Most Valuable Professional
Most Valuable Professional

The reason recursion is supported in Datamart is that its backended by Azure SQL Database while the Lakehouse SQL Endpoint and Warehouse are a new MPP engine (started with Synapse Serverless).  With Fabric, MS have built a SQL engine from scratch with fundamentally different architecture to SQL Server/Azure SQL Database so not everything we expect will be there right now, if at all.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.