UNION Types Mismatch

From: "CN" <cnliou9(at)fastmail(dot)fm>
To: pgsql-bugs(at)postgresql(dot)org
Subject: UNION Types Mismatch
Date: 2003-04-23 05:51:50
Message-ID: 20030423055150.85BD14DC3D@smtp.us2.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message hvicha 2003-04-23 06:55:49 Re: Bug #952: real type in WHERE
Previous Message pgsql-bugs 2003-04-23 00:14:15 Bug #953: pg_dump dies on tables with no columns