Re: Old question - failed to find conversion function from "unknown"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ilejn(at)yandex(dot)ru
Cc: dev(at)archonet(dot)com, pgsql-general(at)postgresql(dot)org
Subject: Re: Old question - failed to find conversion function from "unknown"
Date: 2005-07-19 14:17:35
Message-ID: 23591.1121782655@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

"Ilja Golshtein" <ilejn(at)yandex(dot)ru> writes:
>> Well, it would obviously be better if PG could figure out it was safe,
>> but I'm not sure there's a general case where it is. You can see it's OK
>> because you know there's only one row in your SELECT result-set.

> I think, it's OK because NULL can be compared with anything
> with predictable result and no additional information about
> types is necessary.
> Is it correct vision?

The backend doesn't really distinguish NULL from 'foo' (or untyped
string literals in general) when making datatype decisions. If we
were to change the behavior of
select 1 where 5 in (select null)
at all, it would undoubtedly be to treat it as
select 1 where 5 in (select null::text)
because TEXT is the default resolution for UNKNOWN in every other
case where we force a choice to be made. But this is not what you
want for your example, and in general it would probably break as
many cases as it fixed. So I'm inclined to leave it as-is ---
an error message is probably better than a surprising silent choice.

My recommendation is to cast the NULL to the right type explicitly.

regards, tom lane

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Richard Huxton 2005-07-19 14:18:28 Re: Old question - failed to find conversion function from
Previous Message Tom Lane 2005-07-19 14:05:43 Re: dump/restore needed when switching from 32bit to 64bit processor architecture?

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-07-19 14:18:28 Re: Old question - failed to find conversion function from
Previous Message Alex Stapleton 2005-07-19 14:06:47 Stored Procedures for Security