For a short summary - I want to set a variable equal to the amount of rows present or amount of data entries present in a table.
I am running a query in my Python script that counts the amount of devices that have been used in my app through the past week. I do this by counting the distinct serial numbers. Currently I am using this query.
#standardsql
SELECT count(distinct serial)
FROM `dataworks-356fa.FirebaseArchive.test2`
Where (PeripheralType = 1 or PeripheralType = 2 or PeripheralType = 12)
AND EXTRACT(WEEK FROM createdAt) = EXTRACT(WEEK FROM CURRENT_TIMESTAMP()) - 1
AND serial != 'null'
I am then sending this result to slack at a later point in my python script with this code.
with open('Count_BB_Serial_weekly.json', 'r') as lowfile:
low = json.load(lowfile)
low1 = low["f0_"]
f0_ = the amount of distinct serial numbers counted
However, now I want to add a function that I can also see the serial numbers which have been used along with the amount of different serial numbers used. The query to list the serial numbers is similar to the above just without the count(distinct) part. Is there a way that I can set low1 equal to the amount of rows in the table because I can not run a count function that also lists the serial numbers. Hopefully you can follow along with this. If there is any confusion I will address it in the comments.
Thank you!
lenoperator. Still, from what I understood from your question, this json is the result of a query ran in BQ. This being the case I wonder if it would be better to bring another field in the results (such asf1_) containing the total rows processed already (let BQ do the work, not python).lenoperator. Still, from what I understood from your question, this JSON is the result of a query ran in BQ. This being the case, I wonder if it would be better to bring another field in the results (such asf1_) containing the total rows processed already (let BQ do the work, not python).