Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDNkt-00068z-Au for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Feb 2014 00:32:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WDNks-0007sj-Rg for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Feb 2014 00:32:46 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDNks-0007sd-4v for pgsql-jdbc@postgresql.org; Wed, 12 Feb 2014 00:32:46 +0000 Received: from mexico.yellowfin.com.au ([210.50.197.134]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDNko-0000Cc-Et for pgsql-jdbc@postgresql.org; Wed, 12 Feb 2014 00:32:45 +0000 Received: from [192.168.4.145] (ppp162-167.static.internode.on.net [150.101.162.167]) (Authenticated sender: peter.damen@yellowfin.com.au) by mexico.yellowfin.com.au (Postfix) with ESMTPSA id 844ED748B26 for ; Wed, 12 Feb 2014 11:36:32 +1100 (EST) Message-ID: <52FAC10F.5030906@peterdamen.com> Date: Wed, 12 Feb 2014 11:32:15 +1100 From: Peter Damen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: JDBC PostgreSQL Stored Procedure Meta-data Content-Type: multipart/alternative; boundary="------------010805060106040008010301" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org This is a multi-part message in MIME format. --------------010805060106040008010301 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello, I have an issue with retrieving meta-data for Stored Procedures using the JDBC driver. I have outlined the details of my issue here: http://stackoverflow.com/questions/21541745/postgresql-9-jdbc-driver-returns-incorrect-metadata-for-stored-procedures# Essentially I have this example stored procedure: *CREATE FUNCTION testproc(itemid int)** **RETURNS TABLE(id int, name varchar(200)) AS $$** **BEGIN** ** RETURN QUERY SELECT ipperson, firstname FROM testtable** ** WHERE id = itemid;** **END;** **$$ LANGUAGE plpgsql;* And I want to get the meta-data for this query using the JDBC DatabaseMetaData. I have written a Java test case, it prints out the parameters returned by the meta-data call: *package com.hof.unittest;** ** **import java.sql.Connection;** **import java.sql.DriverManager;** **import java.sql.ResultSet;** ** **public class TestPostgres {** ** ** public static void main(String args[]) {** ** ** try {** ** ** Class.forName("org.postgresql.Driver");** ** ** Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/testdb", "admin", "admin");** ** ** ResultSet rs = conn.getMetaData().getProcedureColumns(null, null, "testproc", null);** ** ** System.out.println("Driver: " + conn.getMetaData().getDriverVersion());** ** ** while (rs.next()) {** ** ** System.out.println("Parameter Name: " + rs.getString(4) + " Paramter Type: " + rs.getShort(5) + " Data Type: " + rs.getInt(6));** ** ** }** ** ** } catch (Exception e) {** ** e.printStackTrace();** ** }** ** ** }** ** **}* I get different results with different JDBC drivers (against the same 9.1.11 server): *Driver: PostgreSQL 8.0 JDBC3 with SSL (build 313)** **Parameter Name: returnValue Paramter Type: 5 Data Type: 1111** **Parameter Name: $1 Paramter Type: 1 Data Type: 4** ** **Driver: PostgreSQL 9.0 JDBC4 (build 801)** **Parameter Name: itemid Paramter Type: 1 Data Type: 4** **Parameter Name: id Paramter Type: 1 Data Type: 4** **Parameter Name: name Paramter Type: 1 Data Type: 12** ** **Driver: PostgreSQL 9.3 JDBC4 (build 1100)** **Parameter Name: itemid Paramter Type: 1 Data Type: 4** **Parameter Name: id Paramter Type: 1 Data Type: 4** **Parameter Name: name Paramter Type: 1 Data Type: 12* The 8.0 driver returns meta-data in a form I can use.. it says there is one IN parameter and one OUT parameter (the resultset). The 9.0/3 drivers don't return an OUT parameter, and along with the single IN parameter, the columns returned by the resultset are also listed, and listed as a IN parameter. Are the 9 drivers returning the wrong meta-data? Was there change in how procedures were handled between JDBC3 and JDBC4? I need to get meta-data about just the IN parameters for a procedure as I need to dynamically prompt for input values and build the execution string.. ie SELECT * FROM procedure(?) OR { ? = procedure(?) } Is there any other way to get this information... querying system tables etc? Thanks. --------------010805060106040008010301 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hello,

I have an issue with retrieving meta-data for Stored Procedures using the JDBC driver.
I have outlined the details of my issue here: http://stackoverflow.com/questions/21541745/postgresql-9-jdbc-driver-returns-incorrect-metadata-for-stored-procedures#

Essentially I have this example stored procedure:

CREATE FUNCTION testproc(itemid int)
RETURNS TABLE(id int, name varchar(200)) AS $$
BEGIN
    RETURN QUERY SELECT ipperson, firstname FROM testtable
                 WHERE id = itemid;
END;
$$ LANGUAGE plpgsql;

And I want to get the meta-data for this query using the JDBC DatabaseMetaData.

I have written a Java test case, it prints out the parameters returned by the meta-data call:

package com.hof.unittest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class TestPostgres {

    public static void main(String args[]) {

        try {

            Class.forName("org.postgresql.Driver");

            Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/testdb", "admin", "admin");

            ResultSet rs = conn.getMetaData().getProcedureColumns(null, null, "testproc", null);

            System.out.println("Driver: " + conn.getMetaData().getDriverVersion());

            while (rs.next()) {

                System.out.println("Parameter Name: " + rs.getString(4) + " Paramter Type: " + rs.getShort(5) + " Data Type: " + rs.getInt(6));

            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}


I get different results with different JDBC drivers (against the same 9.1.11 server):

Driver: PostgreSQL 8.0 JDBC3 with SSL (build 313)
Parameter Name: returnValue Paramter Type: 5 Data Type: 1111
Parameter Name: $1 Paramter Type: 1 Data Type: 4

Driver: PostgreSQL 9.0 JDBC4 (build 801)
Parameter Name: itemid Paramter Type: 1 Data Type: 4
Parameter Name: id Paramter Type: 1 Data Type: 4
Parameter Name: name Paramter Type: 1 Data Type: 12

Driver: PostgreSQL 9.3 JDBC4 (build 1100)
Parameter Name: itemid Paramter Type: 1 Data Type: 4
Parameter Name: id Paramter Type: 1 Data Type: 4
Parameter Name: name Paramter Type: 1 Data Type: 12


The 8.0 driver returns meta-data in a form I can use.. it says there is one IN parameter and one OUT parameter (the resultset).

The 9.0/3 drivers don't return an OUT parameter, and along with the single IN parameter, the columns returned by the resultset are also listed, and listed as a IN parameter.

Are the 9 drivers returning the wrong meta-data?
Was there change in how procedures were handled between JDBC3 and JDBC4?

I need to get meta-data about just the IN parameters for a procedure as I need to dynamically prompt for input values and build the execution string.. ie SELECT * FROM procedure(?) OR { ? = procedure(?) }

Is there any other way to get this information... querying system tables etc?

Thanks.






--------------010805060106040008010301--