masaya
masaya

Reputation: 490

How can I get Table Name from BigQuery in python

I would like to get only table names from BigQuery by using wildcard in Python.
What I want to do is something like this:

from google.cloud import bigquery
bigquery_client = bigquery.Client()
table_names = bigquery_client.get_something().something('db_name.table_prefix_*')

Can I do something like this?
If I can, What should I do?

Upvotes: 1

Views: 1261

Answers (2)

masaya
masaya

Reputation: 490

I did as SANN3 taught me, like a following:

query = '''select table_name from my_dataset_name.INFORMATION_SCHEMA.TABLES where table_name like 'table_prefix_%' '''
table_names = bigquery_client.query(query).result().to_dataframe()
print(table_names)

then I got table_names :-)

Upvotes: 2

SANN3
SANN3

Reputation: 10069

Table metadata details available in the INFORMATION_SCHEMA. You can run the following query and get the table names using Python SDK.

Query:

SELECT table_name FROM YOUR_DATASET.INFORMATION_SCHEMA.TABLES where table_name like 'table_prefix_%'

Reference:

https://cloud.google.com/bigquery/docs/information-schema-tables

https://cloud.google.com/bigquery/docs/running-queries#python

Upvotes: 4

Related Questions