2017-09-04 25 views
0

我需要將記錄插入到BIGQUERY表中,其中一列的值爲雙引號(「)。 直到現在我還是無法這樣做。 docs建議將引號字符更改爲 ,以便能夠在BigQuery表中加載(「)。但我仍然無法弄清楚如何做到這一點。 在這方面的任何幫助表示讚賞。使用Python在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') 

回答

1

不知道你是什麼樣觀察錯誤,但我只是想運行此完全相同的操作,一切都只是正常工作。

也許你沒有正確地逃避雙引號;這裏有一個測試,我只是跑反對我們BQ:

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

table.reload() 
table.insert_data([data]) 

結果:預期

enter image description here

雙引號被保存。

相關問題