<?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: To get Number of rows inserted after performing an Insert operation into a table in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/119974#M46013</link>
    <description>&lt;P&gt;Hi Hubert, will this work with all DML operations and on all Spark versions? And can i use NUM_AFFECTED_ROWS for all DML operations?&lt;/P&gt;</description>
    <pubDate>Thu, 22 May 2025 13:48:05 GMT</pubDate>
    <dc:creator>Hari_Pakalpati</dc:creator>
    <dc:date>2025-05-22T13:48:05Z</dc:date>
    <item>
      <title>To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31747#M23124</link>
      <description>&lt;P&gt;Consider we have two tables A &amp;amp; B.&lt;/P&gt;&lt;P&gt;qry = """&lt;/P&gt;&lt;P&gt;INSERT INTO Table A&lt;/P&gt;&lt;P&gt;Select * from Table B where Id is null&lt;/P&gt;&lt;P&gt; """&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;spark.sql(qry)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to get the number of records inserted after running this in databricks.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 07:45:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31747#M23124</guid>
      <dc:creator>HariharaSam</dc:creator>
      <dc:date>2022-01-13T07:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31749#M23126</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I am getting an syntax error when I run @@ROW_COUNT after the insert statement.&lt;/P&gt;&lt;P&gt;I am running the code in Databricks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2188i3BF811323563EE45/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 12:39:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31749#M23126</guid>
      <dc:creator>HariharaSam</dc:creator>
      <dc:date>2022-01-13T12:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31751#M23128</link>
      <description>&lt;P&gt;Hi @Kaniz Fatma​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I have tried the way you have mentioned but it still throws an error.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 13:06:19 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31751#M23128</guid>
      <dc:creator>HariharaSam</dc:creator>
      <dc:date>2022-01-13T13:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31752#M23129</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;My requirement here is I will be creating a &lt;B&gt;function using Python code&lt;/B&gt; to perform insert operation to a &lt;B&gt;Delta table&lt;/B&gt; , that is why I am running it in an &lt;B&gt;Python cell&lt;/B&gt;.&lt;/P&gt;&lt;P&gt;I will be passing a table name to that function and  I need to get the number of records inserted into the table once the function is executed.&lt;/P&gt;&lt;P&gt;So any solution to achieve this?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 13:46:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31752#M23129</guid>
      <dc:creator>HariharaSam</dc:creator>
      <dc:date>2022-01-13T13:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31753#M23130</link>
      <description>&lt;P&gt;@@ROWCOUNT is rather T-SQL function not Spark SQL. I haven't found something like that in documentation but there is other way as every insert anyway return num_affected_rows and num_inserted_rows fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So you can for example use &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df.first()['num_inserted_rows'] &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or subquery and select in sql syntax. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am including example screenshots.&lt;/P&gt;&lt;P&gt;&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/2191iC8369CD17EFA36FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&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/2192i3922E470E1A2D64D/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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/2195i3BA02BBEC08E2982/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 10:52:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31753#M23130</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-01-14T10:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31754#M23131</link>
      <description>&lt;P&gt;Hi @Hubert Dudek​&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your approach is working for me.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 14:21:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31754#M23131</guid>
      <dc:creator>HariharaSam</dc:creator>
      <dc:date>2022-01-14T14:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31755#M23132</link>
      <description>&lt;P&gt;Great! Please when you can select as best answer.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 14:54:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31755#M23132</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-01-14T14:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31756#M23133</link>
      <description>&lt;P&gt;@Hubert Dudek​, when I execute a similar piece of code in VSCode executed through databricks-connect, the dataframe contains 1 row with no columns, which is a problem. Executing the same code in a notebook on the same cluster works as you stated. Is this possibly a bug in databricks-connect?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 22:38:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31756#M23133</guid>
      <dc:creator>TimThein</dc:creator>
      <dc:date>2023-06-14T22:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31757#M23134</link>
      <description>&lt;P&gt;Almost same advice than Hubert, I use the history of the delta table :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df_history.select(F.col('operationMetrics')).collect()[0].operationMetrics['numOutputRows']&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can find also other 'operationMetrics' values, like 'numTargetRowsDeleted'.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 08:27:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/31757#M23134</guid>
      <dc:creator>GRCL</dc:creator>
      <dc:date>2023-06-15T08:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/119974#M46013</link>
      <description>&lt;P&gt;Hi Hubert, will this work with all DML operations and on all Spark versions? And can i use NUM_AFFECTED_ROWS for all DML operations?&lt;/P&gt;</description>
      <pubDate>Thu, 22 May 2025 13:48:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/119974#M46013</guid>
      <dc:creator>Hari_Pakalpati</dc:creator>
      <dc:date>2025-05-22T13:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: To get Number of rows inserted after performing an Insert operation into a table</title>
      <link>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/126255#M47663</link>
      <description>&lt;P&gt;in case someone is looking for purely SQL based solution: (add LIMIT 1 to the query if you are looking for last op only)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="java"&gt;select t.timestamp, t.operation, t.operationMetrics.numOutputRows as numOutputRows
from (
DESCRIBE HISTORY &amp;lt;catalog&amp;gt;.&amp;lt;schema&amp;gt;.&amp;lt;table&amp;gt;
) t
where t.operation like "%INSERT%"
order by t.timestamp desc&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 23 Jul 2025 23:28:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/to-get-number-of-rows-inserted-after-performing-an-insert/m-p/126255#M47663</guid>
      <dc:creator>User16653924625</dc:creator>
      <dc:date>2025-07-23T23:28:46Z</dc:date>
    </item>
  </channel>
</rss>

