Thomas Swan <tswan@olemiss.edu> writes:
> select id, null as text from foo union select id, name from foo_child;
> fails with
> unable to trasform {insert whatever type here} into unknown
> Each UNION | EXCEPT | INTERSECT clause must have compatible target
> types
The UNION type-resolution code could use some work; right now I think
the algorithm is to use the types of the first SELECT and force
everything else into that. A more symmetrical
promote-to-common-supertype approach would be nice. The UNION code is
such a mess that I haven't wanted to touch it until we do querytree
revisions in 7.2, though.
In the meantime, you should force the NULL to have the datatype you want
with something like "null::text" or "cast (null as text)". Note that
the way you have it above is only assigning a column label that happens
to be "text"; it's not a type coercion.
regards, tom lane