Skip to content

How to get period separated table id from Table Object #354

@JakeSummers

Description

@JakeSummers

I am attempting to build a query using the table id in a bigquery.Table object:

def do_query(client: bigquery.client, table: bigquery.Table):

	statement = f"""
		SELECT *
		FROM {table.full_table_id}
	"""
	query_job = client.query(statement, job_config=job_config)
	result = list(query_job.result())
	...

Unfortunately, this doesn't work. The output of table.full_table_id is: myProject:myDataSet.myTable but queries need to be formatted with period separated values, aka: myProject.myDataSet.myTable.

Question: How should I be constructing queries from a bigquery.Table object?

Right now the work around I am using is this:

statement = f"""
    SELECT *
    FROM {table.project}.{table.dataset_id}.{table.table_id}
"""

But this feels icky.

To search find this issue, this is the exception I was getting:

Traceback (most recent call last):
  ...
  File "me.py", line 74, in me
	result = list(query_job.result())
  File "/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/job.py", line 3230, in result
	super(QueryJob, self).result(retry=retry, timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/job.py", line 835, in result
	return super(_AsyncJob, self).result(timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/google/api_core/future/polling.py", line 130, in result
	raise self._exception
google.api_core.exceptions.BadRequest: 400 Syntax error: Unexpected ":" at [3:30]

I can see from issue #115 that this is the intended behaviour of full_table_id, but I am still curious if there is a cleaner solution to what I am doing.

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions