pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kelly Burkhart <kelly@tradebotsystems.com>
To: pgsql-odbc@postgresql.org
Subject: Re: Insert SHRT_MIN fails for int2 column
Date: Mon, 07 Mar 2005 12:42:34 -0600
Message-ID: <1110220954.3206.20.camel@krb06> (raw)
In-Reply-To: <3084.1110217475@sss.pgh.pa.us>
References: <1110212157.3206.10.camel@krb06>
	<3084.1110217475@sss.pgh.pa.us>

On Mon, 2005-03-07 at 11:44, Tom Lane wrote:
> 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.

Attached is a patch to resolve this.  BTW, is it appropriate for me to
send pgsqlodbc patches to this list?  Or should I send all patches to
psql-patches?

-K

Attachments:

psqlodbc_castshort.patch (text/x-patch, 660B) download --- psqlodbc-08.00.0101/convert.c 2005-01-17 04:12:52.000000000 -0600 +++ psqlodbc-08.00.0101.patch/convert.c 2005-03-07 12:14:18.653080285 -0600 @@ -2989,6 +2989,11 @@ if (param_sqltype == SQL_BIT) CVT_APPEND_CHAR(qb, '\''); /* Open Quote */ + if (param_sqltype == SQL_SMALLINT) + { + CVT_APPEND_STR(qb, "("); + } + if (buf) { switch (used) @@ -3008,7 +3013,7 @@ if (param_sqltype == SQL_SMALLINT) { /* needs cast because there is no automatic downcast from int4 constants */ - CVT_APPEND_STR(qb, "::int2"); + CVT_APPEND_STR(qb, ")::int2"); } if (param_sqltype == SQL_BIT)

view thread (4+ messages)  latest in thread

Message-ID: <1110220954.3206.20.camel@krb06>
Permalink:  ../1110220954.3206.20.camel@krb06/
Also on:    postgresql.org/message-id/1110220954.3206.20.camel@krb06

 ·  · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: kelly@tradebotsystems.com
  Subject: Re: Insert SHRT_MIN fails for int2 column
  In-Reply-To: <1110220954.3206.20.camel@krb06>
  References: <1110212157.3206.10.camel@krb06> <3084.1110217475@sss.pgh.pa.us> <1110220954.3206.20.camel@krb06>

* 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