cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Error when accessing 'num_inserted_rows' in Spark SQL (DBR 15.4 LTS)

Buranapat
Visitor

Hello Databricks Community,

I've encountered an issue while trying to capture the number of rows inserted after executing an SQL insert statement in Databricks (DBR 15.4 LTS). My code is attempting to access the number of inserted rows as follows:

 

rows_insert = spark.sql(insert_statement).first()['num_inserted_rows']

 

However, I am receiving the following error:

 

TypeError: 'NoneType' object is not subscriptable

 

Upon further investigation, I noticed that in the SQL execution result, the fields num_affected_rows and num_inserted_rows are shown, but no rows are actually returned. This can be seen in the screenshots I've attached:

  • The first image shows the result of my SQL insert, which displays the columns num_affected_rows and num_inserted_rows but with no actual rows returned.
    Buranapat_4-1727751428815.png

     

  • The second image shows the subsequent Python error when I try to access num_inserted_rows from the result.
    Buranapat_3-1727750986067.png

Has anyone else faced a similar issue? I would greatly appreciate any insights or suggestions on how to work around this problem.

Thanks in advance for your help!

0 REPLIES 0

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group