Search code examples
google-bigquerycoalesce

Correct use of COALESCE() in BigQuery


I'm running the following script:

select COALESCE(test1,test2,test3)
from (select null as test1,'' as test2,'fdsda' as test3)

and receive the following error:

No matching signature for function COALESCE for argument types: INT64, STRING, STRING. Supported signature: COALESCE([ANY, ...]) at [1:8]

Any idea for the reason of this error?


Solution

  • Use

    select COALESCE(test1,test2,test3) from (select cast(null as string) as test1,'' as test2,'fdsda' as test3)
    

    Anyway, I agree with rmesteves - different types in coalesce do not make sense.