From jrobette@onyme.com Tue Oct 5 16:25:51 2004 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5FC9D32A111; Tue, 5 Oct 2004 17:25:51 +0100 (BST) 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 67333-04; Tue, 5 Oct 2004 16:25:47 +0000 (GMT) Received: from dns.cegetel-passerelle.com (dns.cegetel-passerelle.com [213.223.187.134]) by svr1.postgresql.org (Postfix) with ESMTP id A930E32A0FE; Tue, 5 Oct 2004 17:25:40 +0100 (BST) Received: from escmail.esc-lille.fr (unknown [213.223.237.160]) by dns.cegetel-passerelle.com (Postfix) with ESMTP id 0AD462533A; Tue, 5 Oct 2004 18:25:36 +0200 (CEST) Received: from srvmail.esc-lille.fr (srvmail.esc-lille.fr [10.1.10.5]) by escmail.esc-lille.fr (Postfix) with ESMTP id C1DEA67C134; Tue, 5 Oct 2004 18:24:43 +0200 (CEST) Received: from Johann ([10.10.1.165]) by srvmail.esc-lille.fr with Microsoft SMTPSVC(5.0.2195.6713); Tue, 5 Oct 2004 18:25:35 +0200 From: "Johann Robette" To: Cc: Subject: Postgres 8.0 + JDBC Date: Tue, 5 Oct 2004 18:25:52 +0200 Message-ID: <002901c4aaf7$feabc310$a5010a0a@Johann> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_002A_01C4AB08.C2349310" X-Priority: 1 (Highest) X-MSMail-Priority: High X-Mailer: Microsoft Outlook, Build 10.0.2627 Importance: High X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-OriginalArrivalTime: 05 Oct 2004 16:25:35.0319 (UTC) FILETIME=[F12E1670:01C4AAF7] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.8 tagged_above=0.0 required=5.0 tests=HTML_30_40, HTML_MESSAGE, X_MSMAIL_PRIORITY_HIGH, X_PRIORITY_HIGH X-Spam-Level: * X-Archive-Number: 200410/184 X-Sequence-Number: 66709 This is a multi-part message in MIME format. ------=_NextPart_000_002A_01C4AB08.C2349310 Content-Type: multipart/alternative; boundary="----=_NextPart_001_002B_01C4AB08.C2349310" ------=_NextPart_001_002B_01C4AB08.C2349310 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hello, I have an application running under JBoss. Up to today, I was using Postgres 7.3 and the appropriate version of the jdbc driver. In my application, I have to call a user-defined function which accept in parameters 2 arrays. Here is the header of my function : CREATE OR REPLACE FUNCTION getmembers(int8, int8, _text, _float8) So I called it using a prepared statement with setArray() : double[] weights = {0.5}; String[] names = {"foo1", "foo2"}; java.sql.Array a_names = PostgresArray.create(names); java.sql.Array a_weights = PostgresArray.create(weights); ps = conn.prepareStatement("SELECT * FROM getmembers(?,?,?::_text,?::_float8);"); ps.setLong(1, 1); ps.setLong(2, 2); ps.setArray(3, a_names); ps.setArray(4, a_weights); ps.executeQuery(); PostgresArray is a class which I found on the archives.postgresql.org. The code is given is attached. All worked fine. But today, I decided to upgrade to Postgres 8.0 beta 3. No problem with the definition of my function. I downloaded the appropriate JDBC driver : pgdev.306.jdbc3.jar. Now running the same code as before, I get the error while executing the query : java.sql.SQLException: ERROR: cannot cast type text to text[] So, what am I doing wrong? Is it a beta bug or is my code incorrect? What is the correct way to use SetArray()? Thanks JR ------=_NextPart_001_002B_01C4AB08.C2349310 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hello,

 

I have an application ru= nning under JBoss.

Up to today, I was using= Postgres 7.3 and the appropriate version of the jdbc driver.

In my application, I hav= e to call a user-defined function which accept in parameters 2 arrays. Here is the header of my function = :

            =     CREATE OR REPLACE FUNCTION getmembers(int8, int8, _text, _float8)

So I called it using a prepared statement with setArray() :

            =     double[] weights =3D {0.5};

      String[] names =3D {“foo1”, “foo2= 221;};

      java.sql.Array a_names = =3D PostgresArray.create(names);

      java.sql.Array a_weights = =3D PostgresArray.create(weights);

      ps =3D conn.prepareStatement("SELECT * FROM getmembers(?,?,?::_text,?::_float8);&quo= t;);

      ps.setLong(1, 1);

      ps.setLong(2, 2);

      ps.setArray(3, a_names);

     = ps.setArray(4, a_weights);=

      ps.executeQuery();

 =

PostgresArr= ay is a class which I found on the archives.postgresql.org. The code is given is attached.

 =

All worked = fine.

 =

But today, I decided to upgrade to Postgres 8.0 beta 3.

 =

No problem with the defi= nition of my function.

I downloaded the appropr= iate JDBC driver : pgdev.306.jdbc3.jar.

 =

Now running the same cod= e as before, I get the error while executing the query :

            =     java.sql.SQLExcep= tion: ERROR: cannot cast type text to text[]

 =

So, what am I doing wron= g?

Is it a beta bug or is m= y code incorrect?

What is the correct way = to use SetArray()?

 =

Thanks=

 =

JR

 =

------=_NextPart_001_002B_01C4AB08.C2349310-- ------=_NextPart_000_002A_01C4AB08.C2349310 Content-Type: text/plain; name="PostgresArray.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="PostgresArray.txt" package com.postgresql; import java.math.BigDecimal; import java.sql.*; import java.util.ArrayList; import java.util.Map; /* * Array is used collect one column of query result data. * *

Read a field of type Array into either a natively-typed * Java array object or a ResultSet. Accessor methods provide * the ability to capture array slices. * *

Other than the constructor all methods are direct implementations * of those specified for java.sql.Array. Please refer to the javadoc * for java.sql.Array for detailed descriptions of the functionality * and parameters of the methods of this class. * * This class stolen from postgresql 7.2.1's source tree!!! * * @see ResultSet#getArray * */ public class PostgresArray implements Array { private String rawString =3D null; private String typeName =3D null; private int baseType =3D -1; private static final String jdbc2Types[] =3D { "int2", "int4", "oid", "int8", "cash", "money", "numeric", "float4", "float8", "bpchar", "char", "char2", "char4", "char8", "char16", "varchar", "text", "name", "filename", "bytea", "bool", "date", "time", "abstime", "timestamp", "timestamptz", "_bool", "_char", "_int2", "_int4", "_text", "_oid", "_varchar", "_int8", "_float4", "_float8", "_abstime", "_date", "_time", "_timestamp", "_numeric", "_bytea" }; /* * This table holds the JDBC type for each entry above. * * Note: This must be in the same order as above * * Tip: keep these grouped together by the Types. value */ private static final int jdbc2Typei[] =3D { Types.SMALLINT, Types.INTEGER, Types.INTEGER, Types.BIGINT, Types.DOUBLE, Types.DOUBLE, Types.NUMERIC, Types.REAL, Types.DOUBLE, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.C= HAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BINARY, Types.BIT, Types.DATE, Types.TIME, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY }; /* * Create a new Array * * @param conn a database connection * @param idx 1-based index of the query field to load into this Ar= ray * @param field the Field descriptor for the field to load into thi= s Array * @param rs the ResultSet from which to get the data for this Array */ PostgresArray(String rawString, int baseType, String typeName) throws S= QLException { this.rawString =3D rawString; this.baseType =3D baseType; this.typeName =3D typeName; if (this.typeName.startsWith("_")) { this.typeName =3D this.typeName.substring(1); } } public static Array create(Object[] array) throws SQLException { throw new SQLException("Not Implemented"); } public static Array create(int[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.INTEGER, "int"); } public static Array create(boolean[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.BIT, "boolean"); } public static Array create(long[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.BIT, "bigint"); } public static Array create(BigDecimal[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.NUMERIC, "NUMERIC"); } public static Array create(float[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.REAL, "float"); } public static Array create(double[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.DOUBLE, "double"); } public static Array create(char[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.CHAR, "char"); } public static Array create(String[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.VARCHAR, "varchar"); } public static Array create(Date[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.DATE, "date"); } public static Array create(java.util.Date[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(new Date(array[x].getTime())).append("\"= "); } sb.append("}"); return new PostgresArray(sb.toString(), Types.DATE, "date"); } public static Array create(Time[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.TIME, "time"); } public static Array create(Timestamp[] array) throws SQLException { if (array =3D=3D null) return new PostgresArray(null, -1, null); StringBuffer sb =3D new StringBuffer("{"); for (int x =3D 0; x < array.length; x++) { if (x > 0) sb.append(","); sb.append("\"").append(array[x]).append("\""); } sb.append("}"); return new PostgresArray(sb.toString(), Types.TIMESTAMP, "timestamp= "); } public Object getArray() throws SQLException { return getArray(1, 0, null); } public Object getArray(long index, int count) throws SQLException { return getArray(index, count, null); } public Object getArray(Map map) throws SQLException { return getArray(1, 0, map); } public Object getArray(long index, int count, Map map) throws SQLExcept= ion { /*if (map !=3D null) // For now maps aren't supported. throw new SQLException("Maps are not supported in Array.getArra= y"); if (index < 1) throw new SQLException("index < 1"); Object retVal =3D null; ArrayList array =3D new ArrayList(); if (rawString !=3D null) { char[] chars =3D rawString.toCharArray(); StringBuffer sbuf =3D new StringBuffer(); boolean foundOpen =3D false; boolean insideString =3D false; for (int i =3D 0; i < chars.length; i++) { if (chars[i] =3D=3D '{') { if (foundOpen) // Only supports 1-D arrays for now throw org.postgresql.Driver.notImplemented(); foundOpen =3D true; continue; } if (chars[i] =3D=3D '"') { insideString =3D !insideString; continue; } if ((!insideString && chars[i] =3D=3D ',') || chars[i] =3D= =3D '}' || i =3D=3D chars.length - 1) { if (chars[i] !=3D '"' && chars[i] !=3D '}' && chars[i] = !=3D ',') sbuf.append(chars[i]); array.add(sbuf.toString()); sbuf =3D new StringBuffer(); continue; } sbuf.append(chars[i]); } } String[] arrayContents =3D (String[]) array.toArray(new String[arra= y.size()]); if (count =3D=3D 0) count =3D arrayContents.length; index--; if (index + count > arrayContents.length) throw new SQLException("index + count > arrayContents"); int i =3D 0; switch (getBaseType()) { case Types.BIT: retVal =3D new boolean[count]; for (; count > 0; count--) ((boolean[]) retVal)[i++] =3D ResultSet_ClientSide.toBo= olean(arrayContents[(int) index++]); break; case Types.SMALLINT: case Types.INTEGER: retVal =3D new int[count]; for (; count > 0; count--) ((int[]) retVal)[i++] =3D ResultSet_ClientSide.toInt(ar= rayContents[(int) index++]); break; case Types.BIGINT: retVal =3D new long[count]; for (; count > 0; count--) ((long[]) retVal)[i++] =3D ResultSet_ClientSide.toLong(= arrayContents[(int) index++]); break; case Types.NUMERIC: retVal =3D new BigDecimal[count]; for (; count > 0; count--) ((BigDecimal[]) retVal)[i] =3D ResultSet_ClientSide.toB= igDecimal(arrayContents[(int) index++], 0); break; case Types.REAL: retVal =3D new float[count]; for (; count > 0; count--) ((float[]) retVal)[i++] =3D ResultSet_ClientSide.toFloa= t(arrayContents[(int) index++]); break; case Types.DOUBLE: retVal =3D new double[count]; for (; count > 0; count--) ((double[]) retVal)[i++] =3D ResultSet_ClientSide.toDou= ble(arrayContents[(int) index++]); break; case Types.CHAR: case Types.VARCHAR: retVal =3D new String[count]; for (; count > 0; count--) ((String[]) retVal)[i++] =3D arrayContents[(int) index+= +]; break; case Types.DATE: retVal =3D new Date[count]; for (; count > 0; count--) ((Date[]) retVal)[i++] =3D ResultSet_ClientSide.toDate(= arrayContents[(int) index++]); break; case Types.TIME: retVal =3D new Time[count]; for (; count > 0; count--) ((Time[]) retVal)[i++] =3D ResultSet_ClientSide.toTime(= arrayContents[(int) index++]); break; case Types.TIMESTAMP: retVal =3D new Timestamp[count]; for (; count > 0; count--) ((Timestamp[]) retVal)[i++] =3D ResultSet_ClientSide.to= Timestamp(arrayContents[(int) index]); break; // Other datatypes not currently supported. If you are rea= lly using other types ask // yourself if an array of non-trivial data types is really= good database design. default: throw new SQLException(getBaseType() + "(" + this.typeName = + ") is an unsupported array type"); } return retVal;*/ throw new SQLException("Array.getArray() not supported"); } public int getBaseType() throws SQLException { int sqlType =3D Types.OTHER; // default value for (int i =3D 0; i < jdbc2Types.length; i++) { if (this.typeName.equals(jdbc2Types[i])) { sqlType =3D jdbc2Typei[i]; break; } } return sqlType; } public String getBaseTypeName() throws SQLException { return this.typeName; } public java.sql.ResultSet getResultSet() throws SQLException { return getResultSet(1, 0, null); } public java.sql.ResultSet getResultSet(long index, int count) throws SQ= LException { return getResultSet(index, count, null); } public java.sql.ResultSet getResultSet(Map map) throws SQLException { return getResultSet(1, 0, map); } public java.sql.ResultSet getResultSet(long index, int count, Map map) = throws SQLException { throw new SQLException("Array.getResultSet() not supported"); } public String toString() { return rawString; } } ------=_NextPart_000_002A_01C4AB08.C2349310-- From oliver@opencloud.com Tue Oct 5 20:11:47 2004 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 A342C32A1AE for ; Tue, 5 Oct 2004 21:11:47 +0100 (BST) 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 33856-10 for ; Tue, 5 Oct 2004 20:11:40 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 3DBF032A1AD for ; Tue, 5 Oct 2004 21:11:39 +0100 (BST) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1CEve9-00074u-00; Wed, 06 Oct 2004 09:10:53 +1300 Message-ID: <4162FFC9.3010808@opencloud.com> Date: Wed, 06 Oct 2004 09:10:49 +1300 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Johann Robette Cc: pgsql-jdbc@postgresql.org Subject: Re: Postgres 8.0 + JDBC References: <002901c4aaf7$feabc310$a5010a0a@Johann> In-Reply-To: <002901c4aaf7$feabc310$a5010a0a@Johann> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/15 X-Sequence-Number: 11120 Johann Robette wrote: > java.sql.SQLException: ERROR: cannot cast type text to > text[] setArray has never worked particularly well; you're seeing another manifestation here. The underlying problem here is that: - setArray() is claiming that the type it is setting is a VARCHAR - the parameter is being passed as a typed parameter via the V3 protocol, with type = 'text' - apparently you can't cast directly from text -> text[] (although you can interpret an untyped literal as text[], which is why it worked before). It seems possible to fix the driver to handle this case by making setArray() derive a proper array type name i.e. ("_" + Array.getBaseType()), and using that rather than 'text' as the parameter type. I'll try to do this soon, but I'm a bit busy so it may be a few days. A longer term fix is to properly implement array support in setArray().. I've submitted patches in the past to do this but they've never made it into the official driver. -O From books@ejurka.com Tue Oct 5 20:31:53 2004 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 7A4D032A566 for ; Tue, 5 Oct 2004 21:31:53 +0100 (BST) 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 42860-06 for ; Tue, 5 Oct 2004 20:31:49 +0000 (GMT) Received: from mail63.csoft.net (leary3.csoft.net [63.111.22.74]) by svr1.postgresql.org (Postfix) with SMTP id 9E99A32A10D for ; Tue, 5 Oct 2004 21:31:44 +0100 (BST) Received: (qmail 26533 invoked by uid 1112); 5 Oct 2004 20:31:39 -0000 Date: Tue, 5 Oct 2004 15:31:39 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Oliver Jowett Cc: Johann Robette , pgsql-jdbc@postgresql.org Subject: Re: Postgres 8.0 + JDBC In-Reply-To: <4162FFC9.3010808@opencloud.com> Message-ID: References: <002901c4aaf7$feabc310$a5010a0a@Johann> <4162FFC9.3010808@opencloud.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= X-Spam-Level: X-Archive-Number: 200410/16 X-Sequence-Number: 11121 On Wed, 6 Oct 2004, Oliver Jowett wrote: > It seems possible to fix the driver to handle this case by making > setArray() derive a proper array type name i.e. ("_" + > Array.getBaseType()), and using that rather than 'text' as the parameter > type. > Wouldn't it be simpler to change setArray to call setString with 0 as the type oid allowing the backend to figure out what to do with it? Perhaps it would have trouble determining the type if the underlying function was overloaded, but other than that I don't see a problem. Kris Jurka From oliver@opencloud.com Tue Oct 5 20:57:33 2004 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 30ADB329ED9 for ; Tue, 5 Oct 2004 21:57:33 +0100 (BST) 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 51355-04 for ; Tue, 5 Oct 2004 20:57:22 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 9E132329ED5 for ; Tue, 5 Oct 2004 21:57:22 +0100 (BST) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1CEwN3-0007Gy-00; Wed, 06 Oct 2004 09:57:17 +1300 Message-ID: <41630AAB.7080501@opencloud.com> Date: Wed, 06 Oct 2004 09:57:15 +1300 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kris Jurka Cc: Johann Robette , pgsql-jdbc@postgresql.org Subject: Re: Postgres 8.0 + JDBC References: <002901c4aaf7$feabc310$a5010a0a@Johann> <4162FFC9.3010808@opencloud.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/18 X-Sequence-Number: 11123 Kris Jurka wrote: > > On Wed, 6 Oct 2004, Oliver Jowett wrote: > > >>It seems possible to fix the driver to handle this case by making >>setArray() derive a proper array type name i.e. ("_" + >>Array.getBaseType()), and using that rather than 'text' as the parameter >>type. >> > > > Wouldn't it be simpler to change setArray to call setString with 0 as the > type oid allowing the backend to figure out what to do with it? Perhaps > it would have trouble determining the type if the underlying function was > overloaded, but other than that I don't see a problem. Using the unknown oid seems like it'd introduce more problems: overloading, and the possibility you actually pass your array as some other type unexpectedly. I am wondering if the right way to find the array OID is to prepend "_" and search on pg_type.typname, or to look for pg_type.typinput = (oid of array_in) and pg_type.typelem = (oid of underlying type). Is there a 'standard' way of finding an array type OID? -O From tgl@sss.pgh.pa.us Tue Oct 5 21:28:30 2004 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 B24EA329ECC for ; Tue, 5 Oct 2004 22:28:30 +0100 (BST) 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 60426-04 for ; Tue, 5 Oct 2004 21:28:19 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id F1D29329D9E for ; Tue, 5 Oct 2004 22:28:19 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i95LSDVO018242; Tue, 5 Oct 2004 17:28:13 -0400 (EDT) To: Oliver Jowett Cc: Kris Jurka , Johann Robette , pgsql-jdbc@postgresql.org Subject: Re: Postgres 8.0 + JDBC In-reply-to: <41630AAB.7080501@opencloud.com> References: <002901c4aaf7$feabc310$a5010a0a@Johann> <4162FFC9.3010808@opencloud.com> <41630AAB.7080501@opencloud.com> Comments: In-reply-to Oliver Jowett message dated "Wed, 06 Oct 2004 09:57:15 +1300" Date: Tue, 05 Oct 2004 17:28:12 -0400 Message-ID: <18241.1097011692@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/19 X-Sequence-Number: 11124 Oliver Jowett writes: > I am wondering if the right way to find the array OID is to prepend "_" > and search on pg_type.typname, or to look for pg_type.typinput = (oid of > array_in) and pg_type.typelem = (oid of underlying type). Is there a > 'standard' way of finding an array type OID? The backend does it by name, ie prepend '_' and lookup by typname (and typnamespace). This is a mite unclean but it hasn't seemed worth fixing. If you like you can use the typelem as an additional check that you found the right thing. regards, tom lane From oliver@opencloud.com Thu Oct 7 05:07:19 2004 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 EEACF32A6EA for ; Thu, 7 Oct 2004 06:07:19 +0100 (BST) 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 51474-06 for ; Thu, 7 Oct 2004 05:06:10 +0000 (GMT) Received: from www.postgresql.com (www.postgresql.com [200.46.204.209]) by svr1.postgresql.org (Postfix) with ESMTP id 1D1AC32A7F9 for ; Thu, 7 Oct 2004 06:06:11 +0100 (BST) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by www.postgresql.com (Postfix) with ESMTP id 63BE75A1046 for ; Thu, 7 Oct 2004 06:04:59 +0100 (BST) Received: from flood.opencloud.co.nz ([192.168.0.31]) by yass.opencloud.co.nz with esmtp (Exim 3.35 #1 (Debian)) id 1CFQGq-0003Fs-00 for ; Thu, 07 Oct 2004 17:52:52 +1300 Message-ID: <4164CBA2.80600@opencloud.com> Date: Thu, 07 Oct 2004 17:52:50 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: Postgres 8.0 + JDBC References: <002901c4aaf7$feabc310$a5010a0a@Johann> <4162FFC9.3010808@opencloud.com> In-Reply-To: <4162FFC9.3010808@opencloud.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/34 X-Sequence-Number: 11139 Oliver Jowett wrote: > It seems possible to fix the driver to handle this case by making > setArray() derive a proper array type name i.e. ("_" + > Array.getBaseType()), and using that rather than 'text' as the parameter > type. I've done this (plus tests) and it seems to work OK. I can't generate a patch right now as gborg seems to be having some problems (I get 70% packet loss on the last hop, which pretty much hoses CVS access) -O