pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Stephan Szabo <sszabo@megazone23.bigpanda.com>
Cc: Ludwig Lim <lud_nowhere_man@yahoo.com>
Cc: PostgreSQL Mailing List <pgsql-sql@postgresql.org>
Subject: Re: Weird NULL behavior
Date: Thu, 07 Nov 2002 14:09:24 -0500
Message-ID: <28164.1036696164@sss.pgh.pa.us> (raw)
In-Reply-To: <20021107083423.A97075-100000@megazone23.bigpanda.com>
References: <20021107083423.A97075-100000@megazone23.bigpanda.com>

Stephan Szabo <sszabo@megazone23.bigpanda.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



view thread (5+ messages)  latest in thread

Message-ID: <28164.1036696164@sss.pgh.pa.us>
Permalink:  ../28164.1036696164@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/28164.1036696164@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, sszabo@megazone23.bigpanda.com, lud_nowhere_man@yahoo.com
  Subject: Re: Weird NULL behavior
  In-Reply-To: <28164.1036696164@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox