I tend to agree now with my friend’s recent observation that google cloud documentation is a wreck and doesn’t provide proper examples for some of the basic things in its documentation sdk.
I needed to use the function TableReference. When you search for it you will land in the following page — Class TableReference where it’s not clear on how to use
So here is an example code I was using —
from google.cloud import bigquery
# Create a client object.
client = bigquery.Client()
# Get the project ID.
project_id = "my-project-id"
# Get the dataset ID.
dataset_id = "my-dataset"
# Get the table ID.
table_id = "my-table"
# Create a table reference.
table_ref = bigquery.TableReference(
project_id=project_id,
dataset_id=dataset_id,
table_id=table_id,
)
print(table_ref)
This is the error I was getting
TypeError: TableReference.__init__() takes 3 positional arguments but 4 were given
Fix to be applied is pretty simple.
# Create a table reference using from_string
table_ref = bigquery.TableReference.from_string("{project_id}.{dataset_id}.{table_id}")