Search code examples
google-bigquerycoalesce

Can we do customized COALESCE() in BigQuery?


I've been using COALESCE since the first time I used BQ. So basically it looks for a non-NULL value within the bracket.

Is there any way for us to customize it? For example I have two fields that has values either ACTIVE or INACTIVE. I'd like to know whether one of the value from those fields is ACTIVE.

For example:

  • COALESCE('Inactive', 'Active') returns 'Active'
  • COALESCE('Active', 'Inactive') returns 'Active'
  • COALESCE('Inactive', 'Inactive') returns 'Inactive'

Is it possible to use any function for this purpose? Thank you


Solution

  • Use below instead

    SELECT 
      LEAST('Inactive', 'Active'), 
      LEAST('Active', 'Inactive'),
      LEAST('Inactive', 'Inactive')    
    

    with output

    enter image description here