Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery update how to get number of updated rows

I am using Google Cloud Functions to connect to a Google Bigquery database and update some rows. The cloud function is written using Python 3.

I need help figuring out how to get the result message or the number of updated/changed rows whenever I run an update dml through the function. Any ideas?

from google.cloud import bigquery

def my_update_function(context,data):

    BQ = bigquery.Client()
    query_job = BQ.query("Update table set etc...")
    rows = query_job.result()
    return (rows)

I understand that rows always come back as _emptyrowiterator object. Any way i can get result or result message? Documentation says I have to get it from a bigquery job method. But can't seem to figure it out.

like image 586
James Ching Avatar asked Nov 21 '19 08:11

James Ching


1 Answers

I think that you are searching for QueryJob.num_dml_affected_rows. It contain number of rows affected by update or any other DML statement. If you just paste it to your code instead of rows in return statement you will get number as int or you can create some massage like :

return("Number of updated rows: " + str(job_query.num_dml_affected_rows))

I hope it will help :)

like image 101
vitooh Avatar answered Oct 15 '22 03:10

vitooh