<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127086#M47847</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/177478"&gt;@saurabh_aher&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Look at documentation example. You can't use order by with limit at the same time, because order by prevents early termination of recursion. Load the content of your cte with limit applied to delta table and then you can do whatever you want (I mean order the data according to your needs).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="szymon_dybczak_0-1753960845563.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/18656iA4859A0844A7EB4B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="szymon_dybczak_0-1753960845563.png" alt="szymon_dybczak_0-1753960845563.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;WITH RECURSIVE hierarchy AS (
-- Anchor: start with each employee as their own root (level 0)
SELECT
e.id AS root_id,
e.name AS root_name,
e.id AS emp_id,
e.name AS emp_name,
e.managerId,
0 AS level_id
FROM employees e

UNION ALL

-- Recursive part: find all subordinates
SELECT
h.root_id,
h.root_name,
e.id AS emp_id,
e.name AS emp_name,
e.managerId,
h.level_id + 1 AS level_id
FROM hierarchy h
JOIN employees e
ON e.managerId = h.emp_id
)
SELECT *
FROM hierarchy
LIMIT 150000 /*Put here your number*/&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 31 Jul 2025 11:24:28 GMT</pubDate>
    <dc:creator>szymon_dybczak</dc:creator>
    <dc:date>2025-07-31T11:24:28Z</dc:date>
    <item>
      <title>RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127035#M47832</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have usecase where we requires rows more than 1M. buts recursion is limited to 1M. how to increase this limit in Recursive CTE ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="saurabh_aher_0-1753944326907.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/18644iD2AD86129C47F8C4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="saurabh_aher_0-1753944326907.png" alt="saurabh_aher_0-1753944326907.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="saurabh_aher_1-1753944347987.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/18645iDFFC2C23884AEC4F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="saurabh_aher_1-1753944347987.png" alt="saurabh_aher_1-1753944347987.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 06:47:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127035#M47832</guid>
      <dc:creator>saurabh_aher</dc:creator>
      <dc:date>2025-07-31T06:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127038#M47834</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/177478"&gt;@saurabh_aher&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;According to documentation,&amp;nbsp;this limit can be overridden if the SELECT statement driving the recursive CTE includes a LIMIT clause, which effectively controls the recursion. Did you try that?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 07:02:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127038#M47834</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-07-31T07:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127039#M47835</link>
      <description>&lt;P&gt;yes I tried that but its giving syntax error when its done.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 07:05:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127039#M47835</guid>
      <dc:creator>saurabh_aher</dc:creator>
      <dc:date>2025-07-31T07:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127043#M47836</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="saurabh_aher_0-1753946256350.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/18648i135EF97A5B28FCCE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="saurabh_aher_0-1753946256350.png" alt="saurabh_aher_0-1753946256350.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;example of that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 07:17:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127043#M47836</guid>
      <dc:creator>saurabh_aher</dc:creator>
      <dc:date>2025-07-31T07:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127047#M47837</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/177478"&gt;@saurabh_aher&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;And when you try something like that?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with recursive cte as (
select 1 as n

union all 

select n+1 from cte where n&amp;lt;15

)
select *
from cte
limit 2000000&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 31 Jul 2025 07:25:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127047#M47837</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-07-31T07:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127061#M47843</link>
      <description>&lt;P&gt;Its not working then as well.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 09:19:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127061#M47843</guid>
      <dc:creator>saurabh_aher</dc:creator>
      <dc:date>2025-07-31T09:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127074#M47845</link>
      <description>&lt;P&gt;On my side below approach is working.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%sql
WITH RECURSIVE recursive_cte(n) MAX RECURSION LEVEL 200000 AS (
  SELECT 1
  UNION ALL
  SELECT n + 1 FROM recursive_cte WHERE n &amp;lt; 1050000
)
SELECT * FROM recursive_cte
LIMIT 1050000;&lt;/LI-CODE&gt;&lt;P&gt;But still generating so many rows using recursive call is not the best idea (unless your use case is different and you paste your code just for the sake of example).&lt;BR /&gt;&lt;BR /&gt;But if you want to generate huge number of rows you can take approach suggested by Itzik-Ben-Gan:&lt;/P&gt;&lt;P&gt;&lt;A href="https://sqlperformance.com/2021/01/t-sql-queries/number-series-solutions-1" target="_blank"&gt;Number series generator challenge solutions – Part 1 - SQLPerformance.com&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 10:02:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127074#M47845</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-07-31T10:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127080#M47846</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a Databricks SQL table with the following columns:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;id&lt;/SPAN&gt; | name | managerId | rolename&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;This table contains hierarchical data for all employees in the organization, where each employee has an associated manager (except for the CEO, whose managerId is NULL).&lt;/P&gt;&lt;P&gt;I want to build a new table that &lt;STRONG&gt;flattens the hierarchy&lt;/STRONG&gt;, so that for &lt;STRONG&gt;any given employee ID&lt;/STRONG&gt;, I can retrieve all of their &lt;STRONG&gt;direct and indirect subordinates&lt;/STRONG&gt;, along with each subordinate's &lt;STRONG&gt;level in the hierarchy&lt;BR /&gt;&lt;BR /&gt;the code&amp;nbsp;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;WITH RECURSIVE hierarchy AS (&lt;BR /&gt;-- Anchor: start with each employee as their own root (level 0)&lt;BR /&gt;SELECT&lt;BR /&gt;e.id AS root_id,&lt;BR /&gt;e.name AS root_name,&lt;BR /&gt;e.id AS emp_id,&lt;BR /&gt;e.name AS emp_name,&lt;BR /&gt;e.managerId,&lt;BR /&gt;0 AS level_id&lt;BR /&gt;FROM employees e&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;-- Recursive part: find all subordinates&lt;BR /&gt;SELECT&lt;BR /&gt;h.root_id,&lt;BR /&gt;h.root_name,&lt;BR /&gt;e.id AS emp_id,&lt;BR /&gt;e.name AS emp_name,&lt;BR /&gt;e.managerId,&lt;BR /&gt;h.level_id + 1 AS level_id&lt;BR /&gt;FROM hierarchy h&lt;BR /&gt;JOIN employees e&lt;BR /&gt;ON e.managerId = h.emp_id&lt;BR /&gt;)&lt;BR /&gt;SELECT *&lt;BR /&gt;FROM hierarchy&lt;BR /&gt;ORDER BY root_id, level_id, emp_id;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 10:10:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127080#M47846</guid>
      <dc:creator>saurabh_aher</dc:creator>
      <dc:date>2025-07-31T10:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127086#M47847</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/177478"&gt;@saurabh_aher&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Look at documentation example. You can't use order by with limit at the same time, because order by prevents early termination of recursion. Load the content of your cte with limit applied to delta table and then you can do whatever you want (I mean order the data according to your needs).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="szymon_dybczak_0-1753960845563.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/18656iA4859A0844A7EB4B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="szymon_dybczak_0-1753960845563.png" alt="szymon_dybczak_0-1753960845563.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;WITH RECURSIVE hierarchy AS (
-- Anchor: start with each employee as their own root (level 0)
SELECT
e.id AS root_id,
e.name AS root_name,
e.id AS emp_id,
e.name AS emp_name,
e.managerId,
0 AS level_id
FROM employees e

UNION ALL

-- Recursive part: find all subordinates
SELECT
h.root_id,
h.root_name,
e.id AS emp_id,
e.name AS emp_name,
e.managerId,
h.level_id + 1 AS level_id
FROM hierarchy h
JOIN employees e
ON e.managerId = h.emp_id
)
SELECT *
FROM hierarchy
LIMIT 150000 /*Put here your number*/&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 31 Jul 2025 11:24:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/127086#M47847</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-07-31T11:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: RECURSION_ROW_LIMIT  - how to increase more than 1M ?</title>
      <link>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/149636#M53141</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class=""&gt;&lt;A class="" href="https://community.databricks.com/t5/user/viewprofilepage/user-id/177478" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;saurabh_aher,&lt;/SPAN&gt;&lt;/A&gt;&lt;BR /&gt;I was also facing the same issue. I resolved it by using the LIMIT ALL clause where the recursive CTE is used in the SELECT clause. Additionally, the Databricks Runtime (DBR) version must be 17.2 or above.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 17:21:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/recursion-row-limit-how-to-increase-more-than-1m/m-p/149636#M53141</guid>
      <dc:creator>KapilPatil</dc:creator>
      <dc:date>2026-03-02T17:21:01Z</dc:date>
    </item>
  </channel>
</rss>

