要执行从SQL查询生成的SQL查询,您可以使用以下方法:
方法1:使用客户端库
from google.cloud import bigquery
client = bigquery.Client()
generated_query = 'SELECT * FROM dataset.table WHERE column = "value"'
query_job = client.query(generated_query)
results = query_job.result()
for row in results:
print(row)
方法2:使用SQL模板
SELECT * FROM dataset.table WHERE column = @value
from google.cloud import bigquery
client = bigquery.Client()
query_params = [
bigquery.ScalarQueryParameter("value", "STRING", "your_value"),
]
job_config = bigquery.QueryJobConfig(
query_parameters=query_params
)
query_job = client.query(
"SELECT * FROM `project.dataset.template_name`",
job_config=job_config
)
results = query_job.result()
for row in results:
print(row)
这些方法可用于执行从SQL查询生成的SQL查询。您可以根据具体需求选择适合您的方法。