I am building dynamic sql generator at work and have difficulty with union queries. When i run the following query:
SELECT NULL AS field;
the column type is BOOL
by default and it can be used on union with integer types columns as follows:
SELECT field
FROM
(SELECT 21 AS field),
(SELECT NULL AS field)
this returns successful result. But when I run similar query with string type on one subquery, it fails Here is the query failing with Cannot union tables : Incompatible types. 'field' : STRING 'field' : BOOL:
SELECT field
FROM
(SELECT 'hello' AS field),
(SELECT NULL AS field)
What is the best way to infer types and cast null values. My sql generator should work with several data types on union and I thought null can be used with all types. if null can not be used with string and some other types, is there any 'super' type that can be used to replace null fields?