【发布时间】: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