UNION Types Mismatch - Mailing list pgsql-bugs

From CN
Subject UNION Types Mismatch
Date
Msg-id 20030423055150.85BD14DC3D@smtp.us2.messagingengine.com
Whole thread Raw
Responses Re: UNION Types Mismatch
List pgsql-bugs
Thank you very much for the good product!

v7.3.2.

CREATE TABLE ta (c1 CHAR(1));
CREATE TABLE tb (c1 CHAR(1));
CREATE TABLE tc (c1 SMALLINT);

INSERT INTO ta VALUES('a');
INSERT INTO tb VALUES('b');
INSERT INTO tc VALUES(1);

SELECT c1 AS a,NULL AS b,NULL AS c FROM ta
UNION ALL
SELECT NULL,c1,NULL FROM tb
UNION ALL
SELECT NULL,NULL,c1 FROM tc;

ERROR:  UNION types 'text' and 'smallint' not matched

One union is fine:

SELECT c1 AS a,NULL AS c FROM ta
UNION ALL
SELECT NULL,c1 FROM tc;

It's very difficult for me to cast types because this SQL is dynamically
generated by scripts rather than hard coded:

SELECT c1 AS a,NULL AS b,NULL AS c FROM ta
UNION ALL
SELECT NULL,c1,NULL::SMALLINT FROM tb
UNION ALL
SELECT NULL,NULL,c1 FROM tc;

Can postgreSQL be improved to be smarter with such UNION?

CN

--
http://www.fastmail.fm - A no graphics, no pop-ups email service

pgsql-bugs by date:

Previous
From: pgsql-bugs@postgresql.org
Date:
Subject: Bug #953: pg_dump dies on tables with no columns
Next
From: pgsql-bugs@postgresql.org
Date:
Subject: Bug #954: select distinct array