【问题标题】:Loading double quote character in BigQuery table using Python使用 Python 在 BigQuery 表中加载双引号字符
【发布时间】:2017-09-04 19:56:06
【问题描述】:

我需要将记录插入到 BIGQUERY 表中,其中一列的值为双引号(“)。 直到现在我都无法这样做。我浏览了一些文档,建议将引号字符更改为 能够在 BigQuery 表中加载(“)的其他东西。但我仍然无法弄清楚如何做到这一点。 对此方向的任何帮助表示赞赏。

请在下面找到我一直在使用的插入代码:

bigquery_client = bigquery.Client(project = 'financelcr')
dataset = bigquery_client.dataset('Dataset1')
table = dataset.table('Sample_Table')

# Here, one of the variable value is " which is resulting in error in json creation.
var = '["' + table_uuid + '","' + file_type + '","' + Reporting_Date + '","' + Created + '","' + field + '","' + Dictionary[field] + '","' + Datatype + '"]'

try:
    data = json.loads(var)
    print ("json created")
except:
    print("Error in getting Dataset/table name Or Error in json creation")
else:
    table.reload()
    rows = [data]
    errors = table.insert_data(rows)
    if not errors:
        print('Loaded 1 row into {}:{}'.format(dataset, table))
    else:
        print('Error while Inserting records')

【问题讨论】:

    标签: python-2.7 google-bigquery


    【解决方案1】:

    不确定您观察到什么错误,但我只是尝试运行这个完全相同的操作,一切正常。

    也许你没有正确地转义双引号;这是我刚刚针对我们的 BQ 进行的测试:

    f = '\\"testing\\"'
    var = '[' + '"test","' + '{}",'.format(f) + '5]'
    data = json.loads(var)
    
    table.reload()
    table.insert_data([data])
    

    结果:

    双引号按预期保存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 2013-11-09
      • 2015-01-22
      相关资源
      最近更新 更多