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

From Frank van Vugt
Subject Why is a union of two null-results automatically casted to type text ?
Date
Msg-id 200406151329.31604.ftm.van.vugt@foxi.nl
Whole thread Raw
Responses Re: Why is a union of two null-results automatically casted to type text ?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi all,

Boiling down a problem in one of my queries, I noticed this behaviour.


# select version();
                                version
------------------------------------------------------------------------
 PostgreSQL 7.4.2 on i586-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.3
(1 row)


# select 1 union all select '2';
 ?column?
----------
        1
        2
(2 rows)

# select 1 union select null;
 ?column?
----------
        1

(2 rows)

# select 1 union select * from (select null union select null) as foo;
ERROR:  UNION types integer and text cannot be matched


I guess the last one fails because the second union of two unknown(?) types
gets casted to text, which in turn cannot be processed by the UNION while the
left part is of type integer.

I'm wondering about the reason this cast to text takes place, is this simply
because SQL specs say so?





--
Best,




Frank.


pgsql-general by date:

Previous
From: "Neeraj "
Date:
Subject: Interpreting OSDB Results
Next
From: jseymour@linxnet.com (Jim Seymour)
Date:
Subject: Re: [HACKERS] Release 7.4.3 branded