BigQuery Coalesce

In order to get the return of the first non-NULL value in the expression one can use the COALESCE function in BigQuery.

The input expressions can be of any type such as STRING, DATETIME, etc. but they must be consistent in data type so that the result of which of the expressions/variables used in the coalesce function are of the same type, also known as a Super Type.

BigQuery Coalesce Explained

In general a SELECT statement can list columns, call functions against one or more columns, etc. So if you are looking to find the first non-null value of any column or expressions, then coalesce functions to do that for you programatically. For example if in the following SQL statement Col1 is null, but Col2 has a value it will return the value of Col2 as the aliased column colValNeeded:

SELECT COALESCE(col1, col2, 'N/A') as colValNeeded FROM tableA;
Download The Data Strategy White Paper

DLH.io Data Sync Technical Overview

Get Started

Tell us a bit about you

Stay Up-to-Date on AI & Data Engineering

Please complete this form to get the latest news and information in your inbox with our monthly newsletter on all things data, analytics, and AI engineering.

Sales Funnel