BUG #5974: UNION construct type cast gives poor error message - Mailing list pgsql-bugs

From Jeff Wu
Subject BUG #5974: UNION construct type cast gives poor error message
Date
Msg-id 201104122018.p3CKIlWR042915@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #5974: UNION construct type cast gives poor error message  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
The following bug has been logged online:

Bug reference:      5974
Logged by:          Jeff Wu
Email address:      jwu@atlassian.com
PostgreSQL version: 9.0
Operating system:   Mac OS X
Description:        UNION construct type cast gives poor error message
Details:

The UNION construct (as noted on this page:
http://www.postgresql.org/docs/9.0/static/typeconv-union-case.html) will
cast unknown types to TEXT, however, if you try to do three or more UNIONs
the order in which the UNIONs are executed will cause some columns to be
cast to TEXT prematurely.  The result is a type mismatch error.

For example:
SELECT 1,null,null
UNION
SELECT 2,3,null
UNION
SELECT 3,null,4

will fail while

SELECT 1,null,null::INTEGER
UNION
SELECT 2,3,null
UNION
SELECT 3,null,4

will succeed.

This is not a critical error, but I would say that the error message is
misleading because it is not obvious that Postgres casts unknown columns to
TEXT automatically.

The current error message is:
ERROR: UNION types text and integer cannot be matched

I would suggest something like:
ERROR: UNION types text and integer cannot be matched.  HINT: Postgres casts
unknown types to TEXT by default.


Thanks,

Jeff

pgsql-bugs by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: BUG #5976: Corrupted pages on the production database
Next
From: "John Dickson"
Date:
Subject: BUG #5975: Incorrect result from mod function with cast