Python 2.7 使用Python在BigQuery表中加载双引号字符
我需要将记录插入到BIGQUERY表中,其中一列的值为双引号(“)。 我已经看过一些文档,其中建议将引号字符改为 可以在BigQuery表中加载(“)的其他内容。但我仍然不知道如何做到这一点。 在此方向上的任何帮助都将不胜感激 请在下面找到我一直使用的插入代码:Python 2.7 使用Python在BigQuery表中加载双引号字符,python-2.7,google-bigquery,Python 2.7,Google Bigquery,我需要将记录插入到BIGQUERY表中,其中一列的值为双引号(“)。 我已经看过一些文档,其中建议将引号字符改为 可以在BigQuery表中加载(“)的其他内容。但我仍然不知道如何做到这一点。 在此方向上的任何帮助都将不胜感激 请在下面找到我一直使用的插入代码: bigquery_client = bigquery.Client(project = 'financelcr') dataset = bigquery_client.dataset('Dataset1') table = datase
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')
我不确定你观察到了什么错误,但我只是试着运行完全相同的操作,一切都很好 也许你没有正确地避开双引号;这是我刚刚针对我们的BQ进行的测试:
f = '\\"testing\\"'
var = '[' + '"test","' + '{}",'.format(f) + '5]'
data = json.loads(var)
table.reload()
table.insert_data([data])
结果:
正在按预期保存双引号