Re: Smallint needs explicit cast in psql? - Mailing list pgsql-novice

From Tom Lane
Subject Re: Smallint needs explicit cast in psql?
Date
Msg-id 14334.1342461529@sss.pgh.pa.us
Whole thread Raw
In response to Re: Smallint needs explicit cast in psql?  (Matt Musgrove <MMusgrove@efji.com>)
Responses Re: Smallint needs explicit cast in psql?  (Matt Musgrove <MMusgrove@efji.com>)
List pgsql-novice
Matt Musgrove <MMusgrove@efji.com> writes:
> Tom Lane <tgl@sss.pgh.pa.us> writes:
>> By and large it's best not to use smallint as the declared argument type of a function unless you really have to.

> Thank you for the quick response.

> Is this documented? If so, where?

Well, the initial typing of numeric constants is documented in
http://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS
under 4.1.2.6 Numeric Constants.

The fact that the integer->smallint coercion is assignment and not
implicit is probably not stated anywhere in so many words, but there are
at least a couple of places that say that down-casts to more restricted
types are not normally applied implicitly.  (The only one I remember
offhand is in the CREATE CAST reference page, but I think it's explained
in the main text someplace, possibly in chapter 10.)  In practice I
think people would look into the catalogs, eg with psql's \dC, if they
wanted that particular detail.

I don't believe we say anywhere that "functions with smallint arguments
are a bad idea", if that's what you were looking for.

            regards, tom lane

pgsql-novice by date:

Previous
From: Matt Musgrove
Date:
Subject: Re: Smallint needs explicit cast in psql?
Next
From: Jeff Davis
Date:
Subject: Re: A very simple question about rollback/commit