Re: Prepare Statement

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Jie Liang <jie(at)stbernard(dot)com>
Cc: Kris Jurka <books(at)ejurka(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Prepare Statement
Date: 2004-06-18 23:07:03
Message-ID: 40D37597.9030705@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc pgsql-sql

Jie Liang wrote:
> So, I think that PreparedStatement should have a way at least case a
> String to an Array or a way to create a Array, because of
> conn.prepareStatement("SELECT myfunction('{1,2,3}')") is NOT very
> useful.

One way that might work in the current driver is to use PGobject, which
lets you specify the underlying typename to use:

stmt = conn.preparedStatement("SELECT myfunction(?)");
org.postgresql.util.PGobject obj = new PGobject();
obj.setValue("'{1,2,3}'");
obj.setType("int[]");
stmt.setObject(1, obj);

Untested, but in theory this should work even with
setUseServerPrepare(true) in effect.

Also, if you search the archives, quite some time ago (a year?) I posted
a patch that implemented setArray() better, so that you could pass your
own Array implementation to it and have things work correctly. It's out
of date, but might give you a starting point.

-O

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2004-06-18 23:10:11 Re: proposal for CallableStatements to handle multiple out
Previous Message Tom Lane 2004-06-18 22:47:10 Re: Nested transactions

Browse pgsql-sql by date

  From Date Subject
Next Message Riccardo G. Facchini 2004-06-19 06:03:30 Re: plpgsql - Insert from a record variable?
Previous Message Kris Jurka 2004-06-18 21:47:53 Re: Prepare Statement