X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 96AB53A40CF for ; Wed, 17 Nov 2004 02:45:28 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84902-08 for ; Wed, 17 Nov 2004 02:45:21 +0000 (GMT) Received: from mail63.csoft.net (leary3.csoft.net [63.111.22.74]) by svr1.postgresql.org (Postfix) with SMTP id D8F413A230E for ; Wed, 17 Nov 2004 02:45:24 +0000 (GMT) Received: (qmail 1224 invoked by uid 1112); 17 Nov 2004 02:45:54 -0000 Date: Tue, 16 Nov 2004 21:45:54 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: "enishiseki@juno.com" Cc: pgsql-jdbc@postgresql.org Subject: Re: JDBC calling PL/pgSQL with array parameter In-Reply-To: <20041116.093007.42.454@webmail25.nyc.untd.com> Message-ID: References: <20041116.093007.42.454@webmail25.nyc.untd.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests=TO_ADDRESS_EQ_REAL X-Spam-Level: X-Archive-Number: 200411/123 X-Sequence-Number: 11545 On Tue, 16 Nov 2004, enishiseki@juno.com wrote: > I'm trying to call a PL/pgSQL function from a Java program using > JDBC. The function takes an integer array as an input parameter, > sums the elements of the array, and returns the sum. > > I can successfully call the function from psql as: > SELECT testit('{1,2,3}') > > int [] intArray = {1,2,3}; > stmt.setObject(2, intArray ); > > When I try to run the program, I get the error, > "missing dimension value". > The postgresql jdbc driver does not have support for using setOjbect with array types. If you enable statement logging you will see something like the following command on the backend side: SELECT testarrfunc('[I@fd13b5') If you use the 8.0 driver you will get a better error message: Exception in thread "main" org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of [I. Use setObject() with an explicit Types value to specify the type to use. at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1594) Using the 7.4 driver you can do a setString(x, "{1,2,3}"), but this won't work with the 8.0 driver, for that you need a real java.sql.Array implementation. Kris Jurka