Home > Net >  How to get an individual row in Big Query?
How to get an individual row in Big Query?

Time:11-24

I want to get an individual row from the QueryJob in BQ. My query: select count(*) from ... returns a single row & I want to read the count value which is its first column. So if I can get the first row then I can do row[0] for the first column. I can iterate: row in queryJob but since I require only the first row this seems unneccesary.

Below is what I've tried:

row = self.client.query(count_query)
count = row.result()[0]

This gives an error:

'QueryJob' object is not subscriptable"

How can I get individual rows from queryJob by the row index?

CodePudding user response:

Just do:

row = self.client.query(count_query)
result = row.result().total_rows

This will give the count from the query

CodePudding user response:

you can use to_dataframe():

result = self.client.query(count_query).to_dataframe()

#if you want to result as a integer:
result = self.client.query(count_query).to_dataframe()['first_column_name'].iat[0]
  • Related