<?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 SQL CTE in Databricks or something similar? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28421#M20217</link>
    <description>&lt;P&gt;%sql&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WITH genCTE AS (&lt;/P&gt;&lt;P&gt;SELECT MAX(PredID) + 1 AS PredID, 145 AS SystemID&lt;/P&gt;&lt;P&gt;FROM TableA&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;SELECT PredID + 1&lt;/P&gt;&lt;P&gt;FROM genCTE&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM genCTE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I attempt this, I get an error that genCTE does not exists.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There may be a better way to what I am trying to do.  Currently in the version of databricks we are running, we cant use an identity column.  We are migrating a table and job from SQL Server to databricks.  I can do a full load and pull over the identity column.  But, I need to continue to populate this identity column going forward.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also have a tried a SQL UDF where I can easily grab the MAX(ID) and have tried a row_number function over the top of it, but I cant get it work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully I have done an adequate job of describing this issue.  I simply need continue the IDs and need to do it programmaticly in databricks.  I am hoping I can do this via SQL as well as I am not at all familiar with Python, although I would be open to a Python solution, I would just need a little more hand holding with  it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2022 14:24:25 GMT</pubDate>
    <dc:creator>gbradley145</dc:creator>
    <dc:date>2022-10-07T14:24:25Z</dc:date>
    <item>
      <title>SQL CTE in Databricks or something similar?</title>
      <link>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28421#M20217</link>
      <description>&lt;P&gt;%sql&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WITH genCTE AS (&lt;/P&gt;&lt;P&gt;SELECT MAX(PredID) + 1 AS PredID, 145 AS SystemID&lt;/P&gt;&lt;P&gt;FROM TableA&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;SELECT PredID + 1&lt;/P&gt;&lt;P&gt;FROM genCTE&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM genCTE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I attempt this, I get an error that genCTE does not exists.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There may be a better way to what I am trying to do.  Currently in the version of databricks we are running, we cant use an identity column.  We are migrating a table and job from SQL Server to databricks.  I can do a full load and pull over the identity column.  But, I need to continue to populate this identity column going forward.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also have a tried a SQL UDF where I can easily grab the MAX(ID) and have tried a row_number function over the top of it, but I cant get it work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully I have done an adequate job of describing this issue.  I simply need continue the IDs and need to do it programmaticly in databricks.  I am hoping I can do this via SQL as well as I am not at all familiar with Python, although I would be open to a Python solution, I would just need a little more hand holding with  it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 14:24:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28421#M20217</guid>
      <dc:creator>gbradley145</dc:creator>
      <dc:date>2022-10-07T14:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: SQL CTE in Databricks or something similar?</title>
      <link>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28422#M20218</link>
      <description>&lt;P&gt;not seeing anything wrong , but know that your close to making this work.. I do use CTE's in Databricks SQL. make sure your query works as expected outside the CTE. another work around is make the cte portion into a dataframe then create a view from the dataframe, and use it for joins in your sql statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Oct 2022 17:27:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28422#M20218</guid>
      <dc:creator>byrdman</dc:creator>
      <dc:date>2022-10-09T17:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: SQL CTE in Databricks or something similar?</title>
      <link>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28423#M20219</link>
      <description>&lt;P&gt;Recursive CTEs I havent yet used I got the below eg working with pyspark code &lt;A href="https://medium.com/globant/how-to-implement-recursive-queries-in-spark-3d26f7ed3bc9" alt="https://medium.com/globant/how-to-implement-recursive-queries-in-spark-3d26f7ed3bc9" target="_blank"&gt;How to implement Recursive Queries in Spark | by Akash Chaurasia | Globant | Medium&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 02:39:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28423#M20219</guid>
      <dc:creator>PriyaAnanthram</dc:creator>
      <dc:date>2022-10-10T02:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: SQL CTE in Databricks or something similar?</title>
      <link>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28425#M20221</link>
      <description>&lt;P&gt;You are referencing CTE inside of CTE. That's why it is not working. It would be best if you refactored your query.&lt;span class="lia-inline-image-display-wrapper" image-alt="image.png"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1379i85ED68816FDB7203/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Oct 2022 10:22:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28425#M20221</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-10-16T10:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: SQL CTE in Databricks or something similar?</title>
      <link>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28427#M20223</link>
      <description>&lt;P&gt;Hi @Greg Bradley​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or &lt;B&gt;mark an answer as bes&lt;/B&gt;t? Else please let us know if you need more help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We'd love to hear from you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 03:50:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/sql-cte-in-databricks-or-something-similar/m-p/28427#M20223</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-17T03:50:03Z</dc:date>
    </item>
  </channel>
</rss>

