如何使用Python脚本中的API将引号字符(“”)上载到BigQuery表

2024-05-16 11:25:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从平面文件上传一个记录到BigQuery表。 以下是要上载的示例文件,分隔符为“$”:

LCR_REF_OPS_DEPOSITS$amm_reporting_row:string,amm_section:string,amm_report_row_desc:string,amm_subsection_row:float,amm_subsection_desc:string$$csv$|$REF$1$"$$$$TRUE$Sample file$ALT REF

问题是,在其中一列中,我需要上传引号字符(“),上传失败,因为它。 下面是我使用的API的代码片段:

^{pr2}$

遇到错误:

google.cloud.exceptions.BadRequest: 400 CSV table encountered too many errors, giving up. Rows: 1; errors: 1.

有人能给我一些建议吗?在


Tags: 文件ref示例string记录bigquerydesc平面
1条回答
网友
1楼 · 发布于 2024-05-16 11:25:05

BigQuery的"字符是used as default,用于在读取数据时将记录括起来。在

对于您来说,这可能是一个解决方法:

with open('testfile.txt', 'rb') as source_file:
    job = table.upload_from_file(
        source_file,
        source_format='text/csv',
        field_delimiter='$',
        quote_character='') 

相关问题 更多 >