How to use IFNULL() in BigQuery - Standard SQL?

35,840

Check this doc. I think you need to cast the int_value as a string:

IFNULL(value.string_value, CAST(value.int_value AS STRING)) AS singleValueColumn
Share:
35,840
Milton
Author by

Milton

Learning is a lifelong process.

Updated on July 09, 2022

Comments

  • Milton
    Milton almost 2 years

    I would like to know how to use the IFNULL() BigQuery Standard SQL function properly. This is my current data structure. The columns named "key" and "stringColumn" store strings. Meanwhile, the column named "integerColumn" stores integers:

    enter image description here

    I would like to create a new column named "singleValueColumn" that takes the value of the "stringColumn" or "integerColumn" that is not null:

    enter image description here

    This is my BigQuery Standard SQL query:

    SELECT  key,
            value.string_value as stringColumn,
            value.int_value as integerColumn,
            IFNULL(value.string_value, value.int_value) as singleValueColumn
    
    FROM `com_skytracking_ANDROID.app_events_*`, 
          UNNEST(event_dim) as event,
          UNNEST(event.params) as event_param
    
    WHERE event.name = "order_event"
    

    However, when I run the query I am getting this error:

    Error: No matching signature for function IFNULL for argument types: STRING, INT64. Supported signature: IFNULL(ANY, ANY) at [4:9]
    

    Thanks for your help.

  • Milton
    Milton about 6 years
    Thanks for your answer. The query is running fine now.