Re: no "+" operator for smallint and bigint

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
Cc: PostgreSQL-general <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: no "+" operator for smallint and bigint
Date: 2003-02-24 11:39:09
Message-ID: 20030224113909.GB19304@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Feb 24, 2003 at 08:19:20PM +0900, Jean-Christian Imbeault wrote:
> Postgres (7.3.2) doesn't seem to know how to add smallint's to bigint's ...
>
> PG=# select 8::smallint + 8::bigint;
> ERROR: Unable to identify an operator '+' for types 'smallint' and 'bigint'
> You will have to retype this query using an explicit cast
>
> This is surely just an oversight right?

Actually no. Postgresql's type system is completely generic so it no idea
that bigints and smallints are both numbers and that it can make sense to
add them.

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.

IMHO, there is a virtue in not having the database automatically cast
columns in an effort to guess what you mean. If it's ambiguous, make it
clear.

> I was trying to add two columns, a smallint col to a bigint col, and
> store the result in the bigint col ... only to find to my surprise that
> PostgreSQL didn't know how to add smallints to bigints ...
>
> This will be fixed right? ;)

Well, it not quite a straight forward problem and there has been much
discussion about how to solve it. I think 7.3 is better but I'm not sure.

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Support bacteria! They're the only culture some people have.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Tomcat 2003-02-24 12:00:51 Re: 7.4?
Previous Message Jean-Christian Imbeault 2003-02-24 11:19:20 no "+" operator for smallint and bigint