NULL value in subselect in UNION causes error

Started by Jan Wieckabout 19 years ago3 messageshackers
Jump to latest
#1Jan Wieck
JanWieck@Yahoo.com

Checked it against HEAD and 8.2:

postgres=# select 1, 1, 1 union select * from (select 2, null, 2) two;
ERROR: failed to find conversion function from "unknown" to integer

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jan Wieck (#1)
Re: NULL value in subselect in UNION causes error

Jan Wieck <JanWieck@Yahoo.com> writes:

Checked it against HEAD and 8.2:
postgres=# select 1, 1, 1 union select * from (select 2, null, 2) two;
ERROR: failed to find conversion function from "unknown" to integer

It's always done that. The SQL spec would tell you that you have to
cast the null to some specific type. We allow untyped nulls in contexts
where we can derive a type from reasonably nearby context, but an
integer two levels up and over in another union arm isn't very nearby
IMHO. So I'm not particularly concerned about making this work ...

regards, tom lane

#3Jan Wieck
JanWieck@Yahoo.com
In reply to: Tom Lane (#2)
Re: NULL value in subselect in UNION causes error

On 1/26/2007 3:41 PM, Tom Lane wrote:

Jan Wieck <JanWieck@Yahoo.com> writes:

Checked it against HEAD and 8.2:
postgres=# select 1, 1, 1 union select * from (select 2, null, 2) two;
ERROR: failed to find conversion function from "unknown" to integer

It's always done that. The SQL spec would tell you that you have to
cast the null to some specific type. We allow untyped nulls in contexts
where we can derive a type from reasonably nearby context, but an
integer two levels up and over in another union arm isn't very nearby
IMHO. So I'm not particularly concerned about making this work ...

That explains. Thanks.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #