Re: Why is a union of two null-results automatically casted to type text ? - Mailing list pgsql-general

From Tom Lane
Subject Re: Why is a union of two null-results automatically casted to type text ?
Date
Msg-id 441.1087306414@sss.pgh.pa.us
Whole thread Raw
In response to Why is a union of two null-results automatically casted to type text ?  (Frank van Vugt <ftm.van.vugt@foxi.nl>)
Responses Re: Why is a union of two null-results automatically casted to type text ?  (Frank van Vugt <ftm.van.vugt@foxi.nl>)
List pgsql-general
Frank van Vugt <ftm.van.vugt@foxi.nl> writes:
> # select 1 union select * from (select null union select null) as foo;
> ERROR:  UNION types integer and text cannot be matched

> I'm wondering about the reason this cast to text takes place,

UNION requires assignment of a definite type to the inputs, because
otherwise there's no certainty that we know how to identify distinct
and non-distinct values.  The alternative to assigning TEXT is to
reject the inner UNION outright :-(

            regards, tom lane

pgsql-general by date:

Previous
From: jseymour@linxnet.com (Jim Seymour)
Date:
Subject: Re: [HACKERS] Release 7.4.3 branded
Next
From: Frank van Vugt
Date:
Subject: Re: Why is a union of two null-results automatically casted to type text ?