I am trying to parameterize a specific query I want to run for multiple tables, Im using scalarQueryParameter to pass in strings to be used in specific fields. However, I am trying to pass in the table path that will be used in the FROM clause of the query. All the ways I have tried so far aren't working and I am wondering if what I'm trying to do is even possible.
query_insert = """
INSERT INTO
`my_db.edp_analysis_test.edp_analysis`(
SELECT
DATE(ingestion_time) AS Ingestion_time,
COUNT(ingestion_time) AS Rows_Written,
@table_name AS Table_ID,
@table_schema AS Dataset_ID,
FROM
@table_path
WHERE
ingestion_time IS NOT NULL
GROUP BY
ingestion_time
ORDER BY
ingestion_time)
"""
job_config = bigquery.QueryJobConfig(
query_parameters=[
bigquery.ScalarQueryParameter("table_name", "STRING", "name_val"),
bigquery.ScalarQueryParameter("table_schema", "STRING", "schema_val"),
bigquery.ScalarQueryParameter("table_path", "STRING", "my_db.project.table2")
]
)
query_job = client.query(query_insert, job_config=job_config) # Make an API request.
I have put `` around the @table_path in the query, and also around the table path in the parameters. None of the options have worked, is there another way to go about parameterizing/passing in the table path into the query?