Why is a union of two null-results automatically casted to type text ?

From: Frank van Vugt <ftm(dot)van(dot)vugt(at)foxi(dot)nl>
To: pgsql-general(at)postgresql(dot)org
Subject: Why is a union of two null-results automatically casted to type text ?
Date: 2004-06-15 11:29:31
Message-ID: 200406151329.31604.ftm.van.vugt@foxi.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jim Seymour 2004-06-15 11:40:45 Re: [HACKERS] Release 7.4.3 branded
Previous Message NMB Webmaster 2004-06-15 08:06:41 Re: Different runtime on the same query