Reputation: 59
I need to insert record into BIGQUERY table with one of the column having values as double quotes("). That i am unable to do so till now. I have gone through some docs where it was suggested to change the quote character to something else to be able to load (") in BigQuery table. But i am still not able to figure out how this to be done. Any help in this direction is appreciated.
Please find below the Insertion code that i have been using :
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')
Upvotes: 0
Views: 1296
Reputation: 11787
Not sure what error you are observing but I just tried running this exact same operation and everything just worked fine.
Maybe you are not escaping properly the double-quotes; here's a test I just ran against our BQ:
f = '\\"testing\\"'
var = '[' + '"test","' + '{}",'.format(f) + '5]'
data = json.loads(var)
table.reload()
table.insert_data([data])
Result:
Double-quotes are being saved as expected.
Upvotes: 1