无法使用BigQuery Python API设置目标表
我最近在使用Python API时遇到以下BigQuery错误: google.api_core.exceptions.BadRequest:400无法为脚本设置configuration.query.destinationTable 这是我使用的函数:无法使用BigQuery Python API设置目标表,python,google-bigquery,Python,Google Bigquery,我最近在使用Python API时遇到以下BigQuery错误: google.api_core.exceptions.BadRequest:400无法为脚本设置configuration.query.destinationTable 这是我使用的函数: def execute_bigquery_sql(query, dataset_id, table_id, use_legacy_sql=True, write_disposition='WRITE_TRUNCATE'): client
def execute_bigquery_sql(query, dataset_id, table_id, use_legacy_sql=True, write_disposition='WRITE_TRUNCATE'):
client = bigquery.Client()
job_config = bigquery.QueryJobConfig()
job_config.use_legacy_sql = use_legacy_sql
print("table_id: {table_id}".format(table_id=table_id))
print("dataset_id: {dataset_id}".format(dataset_id=dataset_id))
if table_id:
table_ref = client.dataset(dataset_id).table(table_id)
print("table_ref: {table_ref}".format(table_ref=table_ref))
job_config.destination = table_ref
job_config.write_disposition = write_disposition
job_config.allow_large_results = True
job_config.createDisposition = "CREATE_IF_NEEDED"
query_job = client.query(query,job_config=job_config)
results = query_job.result() # Waits for job to complete.
有人知道可能发生的情况和解决方法吗?错误是自描述性的。脚本不允许设置目标表-相反,您应该使用DML/DDL
解决方法是在没有目标表的情况下重置作业配置感谢您的回复,评论的方向确实正确。在BigQuery中,脚本意味着 这是不允许的,我的问题是:
DECLARE capital int64 default 10000000;
因此,在我的案例中,删除上面的行是修复方法
有趣的是,即使在web界面中
- 如果使用脚本,界面将不允许保存到表:
- 相反,当不使用脚本语句时,您应该看到: