Re: Automatic cast

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
Thread:
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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jagadish Prasath Ramu 2006-05-19 10:09:24 BUG #2444: XA Connections given by posgres driver has auto-commit value false by default
Previous Message Alexandre de Arruda Paes 2006-05-18 22:11:35 Automatic cast