From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
Cc: | Ludwig Lim <lud_nowhere_man(at)yahoo(dot)com>, PostgreSQL Mailing List <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Weird NULL behavior |
Date: | 2002-11-07 19:09:24 |
Message-ID: | 28164.1036696164@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> writes:
> On Thu, 7 Nov 2002, Ludwig Lim wrote:
>> SELECT CAST ( (NULL*NULL) AS NUMERIC(2,0));
>> Cannot cast type '"char"' to '"numeric"'
> It seems to me that it's trying to decide on a type
> for the expression NULL * NULL. It's a NULL, but a
> NULL of what type?
Yeah, and it's picking "char" (the single-byte datatype), because
(a) the NULLs are initially regarded as type UNKNOWN, and (b) if we
don't have any other way to make a decision we try assuming that
UNKNOWNs are of string category, and (c) the only datatype in string
category that has a "*" operator is "char".
I am kind of inclined to remove the arithmetic operators on "char"
(+,-,*,/) in 7.4 --- they don't seem to have any real-world uses,
and as this example illustrates, they are perfectly positioned to
capture cases that probably ought to be errors.
But as you say, the proper solution for Ludwig's problem is to cast the
NULLs themselves to numeric, not the result of the multiplication.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Joost Witteveen | 2002-11-07 19:20:52 | pg_dump, no inserts but \copy? |
Previous Message | Jeff Boes | 2002-11-07 18:16:44 | Quartile (etc) ranking in a SQL statement? |