Re: BUG #1453: NULLs in UNION query

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #1453: NULLs in UNION query
Дата
Msg-id 9878.1107233159@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #1453: NULLs in UNION query  ("" <m.woehling@barthauer.de>)
Ответы Re: BUG #1453: NULLs in UNION query  (Dirk.Lutzebaeck@t-online.de (Dirk Lutzebaeck))
Список pgsql-bugs
"" <m.woehling@barthauer.de> writes:
> The following query should not raise an error ("ERROR:  UNION types text and
> integer cannot be matched"):

> SELECT NULL AS Test
> UNION ALL SELECT NULL
> UNION ALL SELECT 0

Hmm ... it works if you do

SELECT NULL AS Test
UNION ALL (SELECT NULL
UNION ALL SELECT 0)

The problem is that transformSetOperationTree() resolves the column
datatypes one UNION pair at a time, and so the two NULLs default to
"text" before we ever look at the zero.

It's probably possible to rejigger it so that the common type is chosen
considering all the set-operation arms in parallel, but it doesn't seem
like a trivial change.  (Translation: there will not be an immediate
fix.)

As a workaround, perhaps you could cast one or all of the nulls to int
explicitly:

SELECT NULL::int AS Test
UNION ALL SELECT NULL
UNION ALL SELECT 0

            regards, tom lane

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [Feed-back] Installing PostgreSQL 8.0.0 on SPARC/Solaris. Configure and install issues.
Следующее
От: Mehul Doshi-A20614
Дата:
Сообщение: Re: Template1 is locked when pgAdminIII is open