Обсуждение: Automatic cast

Поиск
Список
Период
Сортировка

Automatic cast

От
"Alexandre de Arruda Paes"
Дата:
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 ... :)

Re: Automatic cast

От
Kris Jurka
Дата:

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