【发布时间】:2019-08-26 13:33:51
【问题描述】:
我正在尝试将一些数据插入到已经存在的 bigquery 表中。但我无法将该数据放入表中。
我尝试了 google (insert_rows) 提供的标准示例,但没有成功。我也提到了这个:https://github.com/googleapis/google-cloud-python/issues/5539 我也尝试过将此数据作为元组列表传递,但也存在同样的问题。
from google.cloud import bigquery
import datetime
bigquery_client = bigquery.Client()
dataset_ref = bigquery_client.dataset('my_dataset_id')
table_ref = dataset_ref.table('my_destination_table_id')
table = bigquery_client.get_table(table_ref)
rows_to_insert = [
{u'jobName': 'writetobigquery'},
{u'startDatetime': datetime.datetime.now().strftime('%Y-%m-%d-%H%M%S')},
{u'jobStatus': 'Success'},
{u'logMessage': 'NA'},
]
errors = bigquery_client.insert_rows(table, rows_to_insert)
执行此操作时,我没有收到错误消息,但它没有将任何内容写入表中。如果有人建议对我有用的东西,那就太好了。谢谢!
【问题讨论】:
-
我运行了你提供的 sn-p,它对我来说很好用。唯一的问题是它插入了 4 个不同的行,每行只有一个值。您的表是否已使用正确的架构创建?您是否查询了该表并且它没有返回任何结果?
-
Python 2.7?是新开发还是更新?
-
@itroulli 该表已经使用正确的架构创建,在 sn-p 上运行后,我正在查询该表,但它没有返回任何数据作为结果。
-
@guillaumeblaquiere 是的,我正在使用 python 2.7(更新)
-
您是否正在执行查询以查找数据?还是您使用免费预览版?
标签: python-2.7 google-cloud-platform insert google-bigquery try-catch