29 Apr 19 · Ryan-Dallas · #bigquery ·   Bookmark   ×

How to perform exception handling in Google Bigquery SQL Functions

When there is an error while computing a SQL Function, it it fails for any of the rows the entire SQL query will abort. You can overcome this by using the SAFE PREFIX in Bigquery

Below are the list of SAFE Functions available in Bigquery.

  • SAFE_ADD
  • SAFE_CONVERT_BYTES_TO_STRING
  • SAFE_DIVIDE
  • SAFE_MULTIPLY
  • SAFE_NEGATE
  • SAFE_OFFSET and SAFE_ORDINAL
  • SAFE_SUBTRACT

When a row fails during computation of a function, Bigquery will throw a NULL Value instead of aborting the entire query.

Best Practice:

It is a best practice to use the safe prefix wherever applicable

Ryan-Dallas

posted on 29 Apr 19

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds