简体   繁体   English

使用Python处理查询中的BigQuery错误

[英]Handle BigQuery error from the querying by using Python

To handle the errors from bigquery I have used - job.errors[0]['message'] and everything was fine so far. 为了处理来自bigquery的错误,我使用了job.errors[0]['message'] ,到目前为止一切都很好。

The issue is when you querying and for example, when you divide the value by 0, BigQuery will show you: 问题出在查询时,例如,当您将值除以0时,BigQuery将显示:

在此处输入图片说明

QUESTION: By using PYTHON - HOW to pick up this error? 问题:通过使用PYTHON-如何选择此错误?

Or, in BigQuery Standard SQL, you can use SAFE_DIVIDE() to avoid error 或者,在BigQuery Standard SQL中,您可以使用SAFE_DIVIDE()避免错误

SAFE_DIVIDE() is equivalent to the division operator (/), but returns NULL if an error occurs, such as a division by zero error SAFE_DIVIDE()等效于除法运算符(/),但如果发生错误(例如除以零错误),则返回NULL

So instead of SELECT 15 / 0 you should use SAFE_DIVIDE(15, 0) 因此,您应该使用SAFE_DIVIDE(15, 0)而不是SELECT 15 / 0 SAFE_DIVIDE(15, 0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM