How can I use multiple bigquery projects together in python

847 views Asked by At

Suppose I have a big query project A and B. I need to join a table of project A with project B. How I can we join two projects using python.

project_id = 'xyz'
query_job = """SELECT * from test limit 10"""

results_df = gbq.read_gbq(query_job,project_id=project_id, private_key='client_secrets.json')

In the above code, I can use only one project_id. If I need to use multiple codes what can be done for that?

1

There are 1 answers

0
Tamir Klein On BEST ANSWER

The project_Id you pass as part of the request is considered the billing projectId meaning the project from which the cost of the query will be charged.

To use 2 different tables from 2 different projects you need to add the project name to your query using this format projectId.datasetId.tableId

In your example you put only 1 table but it should be like this:

query_job = """SELECT * from projectId.datasetId.test limit 10"""