Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id AAA2E1337B2F for ; Fri, 4 Feb 2011 21:10:42 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 71525-02 for ; Sat, 5 Feb 2011 01:10:31 +0000 (UTC) X-Greylist: delayed 02:57:20.357832 by SQLgrey-1.7.6 Received: from mail-gx0-f174.google.com (mail-gx0-f174.google.com [209.85.161.174]) by mail.postgresql.org (Postfix) with ESMTP id B3A6C133616B for ; Fri, 4 Feb 2011 21:10:28 -0400 (AST) Received: by gxk9 with SMTP id 9so1148480gxk.19 for ; Fri, 04 Feb 2011 17:10:28 -0800 (PST) Received: by 10.90.26.11 with SMTP id 11mr9600527agz.91.1296857587103; Fri, 04 Feb 2011 14:13:07 -0800 (PST) Received: from [10.168.2.218] ([64.245.2.62]) by mx.google.com with ESMTPS id 17sm1380703anx.13.2011.02.04.14.13.05 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 04 Feb 2011 14:13:06 -0800 (PST) Message-ID: <4D4C79D9.1040908@aquafold.com> Date: Fri, 04 Feb 2011 14:12:41 -0800 From: John LH User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.9) Gecko/20100915 Lightning/1.0b2 Thunderbird/3.1.4 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: JDBC CallableStatement bug on functions with return parameter Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.6 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201102/18 X-Sequence-Number: 21416 Hi, I believe there is a bug in the PostgreSQL JDBC driver. I have a function "sales_tax (in subtotal money) RETURNS money" with DDL below. I am trying to execute the function with a CallableStatement. I use the SQL of : { ? = CALL "public"."sales_tax"(?) } I register the parameters and then execute the statement, but it fails with the error message : ERROR: function public.sales_tax(double precision) does not exist I trace the code down to the org.postgresql.jdbc2.AbstractJdbc2Statement.modifyJdbcCall(String p_sql). At the end of this function on line 2384-2410 (Pasted below) it makes a conversion. It seems that the CallableStatement converts the original SQL above to : select * from "public"."sales_tax"(?, ?) as result If you execute this statement with substituted variable a terminal window into PG, the statement will fail. The syntax seems to be incorrect. But the SQL will execute correctly if you execute : select * from "public"."sales_tax"(?) as result I am not sure what is the correct behavior, but this doesn't seem to be correct as I can't execute a function with a return value. Does anyone know if this is a bug or a known limitation? ... or if I am doing something wrong? thanks -John == PROCEDURE DDL ============================================== CREATE OR REPLACE FUNCTION public.sales_tax (in subtotal money) RETURNS money AS $BODY$ BEGIN RETURN subtotal * 0.06; END; $BODY$ LANGUAGE 'plpgsql' GO ================================================================ == AbstractJdbc2Statement.modifyJdbcCall(String p_sql) =============== if (connection.haveMinimumServerVersion("8.1") && ((AbstractJdbc2Connection)connection).getProtocolVersion() == 3) { String s = p_sql.substring(startIndex, endIndex ); StringBuffer sb = new StringBuffer(s); if ( outParmBeforeFunc ) { // move the single out parameter into the function call // so that it can be treated like all other parameters boolean needComma=false; // have to use String.indexOf for java 2 int opening = s.indexOf('(')+1; int closing = s.indexOf(')'); for ( int j=opening; j< closing;j++ ) { if ( !Character.isWhitespace(sb.charAt(j)) ) { needComma = true; break; } } if ( needComma ) { sb.insert(opening, "?,"); } else { sb.insert(opening, "?"); } } return "select * from " + sb.toString() + " as result"; } ================================================================