Re: union query - Mailing list pgsql-general

From Tom Lane
Subject Re: union query
Date
Msg-id 15863.979314079@sss.pgh.pa.us
Whole thread Raw
In response to union query  ("Tamsin" <tg_mail@bryncadfan.co.uk>)
List pgsql-general
"Tamsin" <tg_mail@bryncadfan.co.uk> writes:
>    select 'other' union select description from address;
>    ERROR:  Unable to transform varchar to unknown
>         Each UNION | EXCEPT | INTERSECT clause must have compatible target
> types

The behavior in 7.0.* and before (as far back as I recall) has been that
the first select determines the output type of the union, so the above
fails, but reversing it works.  7.1 is a little smarter about
unknown-type literals, so it accepts both of your cases, but it will
still do the Wrong Thing for examples like select int4 union select int8.

> I just wondered
> if the order of the selects in a union should matter?

It shouldn't, really, but without a complete type promotion hierarchy
we have a hard time doing anything intelligent with arbitrary pairs of
types.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: MacOS X
Next
From: "Nick Fankhauser"
Date:
Subject: Correlated subquery/update