Re: Automatic cast

Lists: pgsql-jdbc
From: "Alexandre de Arruda Paes" <adaldeia(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Automatic cast
Date: 2006-05-18 22:11:35
Message-ID: fe86db180605181511y1980e6f0x74d77d519b5201d5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi,

I have a problem and I want know if this can be solved in the jdbc driver.
Our company develop softwares using a CASE Tool caled Genexus. The
SQL sintaxe are not changeable and they have a big problem: the querys
aren't casted.

SELECT field from table where field=10

If the field are int2 or int8, PostgreSQL don't use indexes (its
converts the value 10 to int4).
Can I put an implicit (automatic) cast (' ' - apostrofes) in the SQL
sintaxes passed throught JDBC ???

Thanks and sorry if this is a stupid question ... :)


From: Kris Jurka <books(at)ejurka(dot)com>
To: Alexandre de Arruda Paes <adaldeia(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Automatic cast
Date: 2006-05-18 22:21:56
Message-ID: Pine.BSO.4.63.0605181718180.17035@leary2.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Thu, 18 May 2006, Alexandre de Arruda Paes wrote:

> I have a problem and I want know if this can be solved in the jdbc driver.
> Our company develop softwares using a CASE Tool caled Genexus. The
> SQL sintaxe are not changeable and they have a big problem: the querys
> aren't casted.
>
> SELECT field from table where field=10
>
> If the field are int2 or int8, PostgreSQL don't use indexes (its
> converts the value 10 to int4).

This should work fine in 8.0 and up when cross type index access was
added. If you're not using 8.0+ consider an upgrade. If you are using
8.0+ please provide more details about your problem.

> Can I put an implicit (automatic) cast (' ' - apostrofes) in the SQL
> sintaxes passed throught JDBC ???

You can write:
SELECT field FROM table WHERE field = ?::int8

or

SELECT field FROM table WHERE field = CAST(? AS int8);

Kris Jurka