Is there a way to list all the table size in BigQuery?
I know a command like this:
select
table_id,
sum(size_bytes)/pow(10,9) as size
from
certain
At the moment there's no possible way to do that in a single query, but you can do it with a script, here is my python script that prints out the list:
from google.cloud import bigquery
client = bigquery.Client()
datasets = list(client.list_datasets())
project = client.project
if datasets:
print('Datasets in project {}:'.format(project))
for dataset in datasets: # API request(s)
print('Dataset: {}'.format(dataset.dataset_id))
query_job = client.query("select table_id, sum(size_bytes)/pow(10,9) as size from `"+dataset.dataset_id+"`.__TABLES__ group by 1")
results = query_job.result()
for row in results:
print("\tTable: {} : {}".format(row.table_id, row.size))
else:
print('{} project does not contain any datasets.'.format(project))