BUG #15129: Problem with UNION/UNION ALL type setting when severalNULL values before defining the proper type - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #15129: Problem with UNION/UNION ALL type setting when severalNULL values before defining the proper type
Date
Msg-id 152196085023.32649.9916472370480121694@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #15129: Problem with UNION/UNION ALL type setting when several NULL values before defining the proper type
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      15129
Logged by:          Philippe BEAUDOIN
Email address:      phb07@apra.asso.fr
PostgreSQL version: 10.3
Operating system:   linux
Description:

While migrating a view from another RDBMS,I reached something that looks lie
a bug in postgres.
It concerns all supported postgres versions.
After a lot of simplification steps, I have a very simple test case that
reproduces the issue.

-- This statement works as expected: the type of the result column is
determined by the type of the first not null value
SELECT NULL
  UNION
SELECT 1::INT;

-- But with an additional NULL value, the statement fails with a message:
"UNION types text and integer cannot be matched"
SELECT NULL
  UNION
SELECT NULL
  UNION
SELECT 1::INT;

-- Adding an explicit cast on the first occurrence fixes the issue (I used
this trick as a workaround)
SELECT NULL::INT
  UNION
SELECT NULL
  UNION
SELECT 1::INT;


pgsql-bugs by date:

Previous
From: Jaime Soler
Date:
Subject: Re: Missed pgq_coop and pgq_ext in actual pgdg repository
Next
From: Andrew Gierth
Date:
Subject: Re: BUG #15129: Problem with UNION/UNION ALL type setting when several NULL values before defining the proper type