Re: Insert SHRT_MIN fails for int2 column - Mailing list pgsql-odbc

From Tom Lane
Subject Re: Insert SHRT_MIN fails for int2 column
Date
Msg-id 3084.1110217475@sss.pgh.pa.us
Whole thread Raw
In response to Insert SHRT_MIN fails for int2 column  (Kelly Burkhart <kelly@tradebotsystems.com>)
Responses Re: Insert SHRT_MIN fails for int2 column  (Kelly Burkhart <kelly@tradebotsystems.com>)
List pgsql-odbc
Kelly Burkhart <kelly@tradebotsystems.com> writes:
> The ::int2 cast is added in convert.c on line 3024 (for 08.00.0005)
> preceded by a comment stating it is necessary:

>     /* needs cast because there is no automatic downcast from
>         int4 constants */
>     CVT_APPEND_STR(qb, "::int2");

> Is this really necessary?  On my 7.4.2 database, the following works
> just fine:

> create table tst ( i16 int2 );
> insert into tst ( i16 ) values ( -32768 );

In that context the down-conversion will work because it's considered an
assignment coercion.  However there are other cases where an explicit
cast is indeed needed, for instance

    select foo(42::int2)

where foo is declared as taking an int2 parameter.

The best thing would be to leave the cast in place but add parentheses
around the value being casted.

            regards, tom lane

pgsql-odbc by date:

Previous
From: jross@wykids.org
Date:
Subject: Re: Installation problem with psqlodbc-08_00_0100.zip
Next
From: jross@wykids.org
Date:
Subject: Unable to connect to PostgreSQL 8.0 with any driver...