setUseServerPrepare & typecasts - Mailing list pgsql-jdbc

From Scott Lamb
Subject setUseServerPrepare & typecasts
Date
Msg-id 3DD22356.2060208@slamb.org
Whole thread Raw
List pgsql-jdbc
I've got a bunch of queries that deal with functions in the custom
functions I've made. So I might have a function foo(integer) returning
text. A simple case:

     ps = conn.prepare("select foo(?)");

and then calling

     ps.setObject(1, new Integer(42), Types.INTEGER);

Without setUseServerPrepare, this works fine. With setUseServerPrepare,
this complains that foo(text) does not exist and suggests explicit
typecasts. With

     select foo(?::integer)

it works again.

Should this be necessary? I am telling it the type of that parameter
before I execute the statement. Does it need to know that at prepare
time? Is the explicit cast in the SQL the only way to do that?

I am using a layer of my own design that creates the placeholders and
binds the parameters for me from named, typed parameters. So I could
easily have it automatically insert "{fn convert(?, <TYPENAME>)}"
instead of "?" into the SQL everywhere I use parameters. Would that be
the best way to fix this problem?

Thanks,
Scott


pgsql-jdbc by date:

Previous
From: Thomas O'Dowd
Date:
Subject: Re: res.wasNull() troubles when using CASE?
Next
From: snpe
Date:
Subject: Re: streaming result sets: progress