Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用BigQuery Python API设置目标表_Python_Google Bigquery - Fatal编程技术网

无法使用BigQuery Python API设置目标表

无法使用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

我最近在使用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 = 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界面中

  • 如果使用脚本,界面将不允许保存到表:

  • 相反,当不使用脚本语句时,您应该看到:

只是澄清一下,在这种情况下脚本是什么意思?这和这个官员有什么不同?好的,那么问题在于实际的SQL操作问题,不是吗?如果该查询不包含任何脚本,那么它将(至少在这方面)工作,对吗?当运行脚本或DML/DDL时,目标是不允许的,并且会导致错误。我遇到了类似的问题,不太理解OP解释的解决方案:我的查询设置看起来像第二个屏幕截图,我无法使用脚本。如何更改查询设置以使用第一个屏幕截图中的脚本?