Re: number to string conversion

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Freddy Villalba Arias <fvillalba(at)madrid(dot)bilbomatica(dot)es>
Cc: PostgreSQL JDBC Mailing List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: number to string conversion
Date: 2004-04-30 11:16:14
Message-ID: 4092357E.4040404@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Eh, sorry, on rereading this it's more than just "how do I set a null
parameter"..

Freddy Villalba Arias wrote:
> Hi everybody,
>
> I wanted to do something like the following:
>
>
>
> SELECT
>
> p.*, (SELECT c.* FROM CCAA c WHERE c.ccaa_id_ccaa = p.prov_id_ccaa)
>
> FROM
>
> PROVINCIA p
>
> WHERE
>
> (prov_id_ccaa = '@@@id_ccaa@@@' OR '' = '@@@id_ccaa@@@') AND
>
> (upper(prov_ds_provincia) LIKE upper('%@@@descripcion@@@%') OR
> '@@@descripcion@@@' = '')
>
>
>
> …where anything between “@@@” is a token that is replaced by some value
> at runtime.
>
>
>
> There is a particular case: null values. In those cases, you’d get a
> query like this:
>
>
>
> SELECT
>
> p.*, (SELECT c.* FROM CCAA c WHERE c.ccaa_id_ccaa = p.prov_id_ccaa)
>
> FROM
>
> PROVINCIA p
>
> WHERE
>
> (prov_id_ccaa = '' OR '' = '') AND
>
> (upper(prov_ds_provincia) LIKE upper('xxx') OR 'xxx' = '')
>
>
>
> Being prov_id_ccaa a numeric column, in ORACLE and Access, this wouldn’t
> pose a problem, but it PostgreSQL it does (it throws the error: ERROR:
> invalid input syntax for type numeric: ")

Well, that makes sense, '' isn't a valid numeric constant. You probably
want to use NULL for this "no value" case, not try to shoehorn it into a
varchar value (i.e. have "... OR ? IS NULL"). But that might have a
different meaning if your schema allows NULLs in those columns.

Alternatively, modify the query based on the actual @@@id_cca@@@ and
@@@descripcion@@@ values being used. You can remove one or both branches
of the AND condition based on their values, entirely on the application
side.

Either way, this is probably better asked on pgsql-sql.

-O

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Andy Zeneski 2004-04-30 15:04:27 Result Set Cursor Patch
Previous Message Oliver Jowett 2004-04-30 11:04:48 Re: number to string conversion