Re: no "+" operator for smallint and bigint - Mailing list pgsql-general

From Tom Lane
Subject Re: no "+" operator for smallint and bigint
Date
Msg-id 3258.1046098784@sss.pgh.pa.us
Whole thread Raw
In response to Re: no "+" operator for smallint and bigint  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: no "+" operator for smallint and bigint  (Dennis Gearon <gearond@cvc.net>)
List pgsql-general
Martijn van Oosterhout <kleptog@svana.org> writes:
> On Mon, Feb 24, 2003 at 08:19:20PM +0900, Jean-Christian Imbeault wrote:
>> PG=3D# select 8::smallint + 8::bigint;
>> ERROR:  Unable to identify an operator '+' for types 'smallint' and 'bigi=
> nt'

> Since there is no explicit operator it doesn't know if the result should be
> a smallint or a bigint so it's asking you to tell it.

More specifically, the parser finds two equally plausible choices: cast the
smallint to int and apply "int4 + int8", or cast the smallint to bigint
and apply "int8 + int8".  Not knowing which to prefer, it has to punt.

> Well, it not quite a straight forward problem and there has been much
> discussion about how to solve it.

That's an understatement :-(.

I currently like the idea of getting rid of as many cross-datatype
operators as possible --- offering a native "int4 + int8" operator
doesn't seem to have any obvious benefit over letting the parser
insert a promotion.  But there are some pitfalls in that idea too.

            regards, tom lane

pgsql-general by date:

Previous
From: Justin Clift
Date:
Subject: Re: A few questions to real pgsql gurus
Next
From: Dmitry Tkach
Date:
Subject: Re: A few questions to real pgsql gurus