From: | "Jie Liang" <jie(at)stbernard(dot)com> |
---|---|
To: | "Kris Jurka" <books(at)ejurka(dot)com> |
Cc: | <pgsql-sql(at)postgresql(dot)org>, <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Re: Prepare Statement |
Date: | 2004-06-18 16:52:18 |
Message-ID: | E7E213858379814A9AE48CA6754F5ECB03451966@mail01.stbernard.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc pgsql-sql |
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.
Comment?
Jie Liang
-----Original Message-----
From: Kris Jurka [mailto:books(at)ejurka(dot)com]
Sent: Thursday, June 17, 2004 10:47 PM
To: Jie Liang
Cc: pgsql-sql(at)postgresql(dot)org; pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [JDBC] Prepare Statement
On Thu, 17 Jun 2004, Jie Liang wrote:
> Kris,
> I have another question, I saw some discussion regarding
> PreparedStatement work with array argument, I get a error when I try
> to play with it. E.g.
> I have myfunction(int[]),
> So,
> PrepareStatement st = conn.prepareStatment("SELECT myfunction(?)");
> String arr="{1,2,3}";
> St.setString(1,arr};
> Result rs = st.executeQuery();
>
> Then it will complaint when it run:
> Myfuntion(text) does not exist!
>
This is actually a case where prepared statements actually cause
trouble.
With the directly executed SELECT myfunction('{1,2,3}'); The backend can
determine that there is only one version of myfunction so it can convert
the unkown argument type to it, but note that this won't work if
myfunction is overloaded.
With the prepared case, you must tell it what types to use when doing
the prepare. The JDBC driver doesn't have a whole lot of information to
work with, so it takes what it knows (that you called setString) and
says the argument is of type text, issuing a prepare like this: PREPARE
JDBC_STATEMENT_1(text) AS SELECT myfunction($1); At this time (before
it actually calls EXECUTE) it tries to lookup myfunction that takes a
text argument and determines there isn't one. In this case it doesn't
have the opportunity to apply any casts because we were quite clear in
specifying that it should take a text argument, not one of unknown type.
Ideally you should be using setArray, but there is no existing way to
create Array objects and I'm not sure that code would work even if there
was.
Kris Jurka
From | Date | Subject | |
---|---|---|---|
Next Message | amo99@libero.it | 2004-06-18 18:00:07 | Pg 7.4.2, jdbc 7.4, data type inet |
Previous Message | Jie Liang | 2004-06-18 16:43:38 | Re: Prepare Statement |
From | Date | Subject | |
---|---|---|---|
Next Message | David B | 2004-06-18 18:29:38 | In 7.4 ensure you have DEFAULT now () with no spaces |
Previous Message | Jie Liang | 2004-06-18 16:43:38 | Re: Prepare Statement |