Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 7467A632343 for ; Thu, 18 Feb 2010 01:34:50 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 00248-07 for ; Thu, 18 Feb 2010 05:34:37 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from leary.csoft.net (leary.csoft.net [205.205.214.5]) by mail.postgresql.org (Postfix) with ESMTP id D0F8C6322CC for ; Thu, 18 Feb 2010 01:34:38 -0400 (AST) Received: by leary.csoft.net (Postfix, from userid 1112) id 0A4E3A3B5; Thu, 18 Feb 2010 00:34:37 -0500 (EST) Date: Thu, 18 Feb 2010 00:34:37 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: list_usr@spacebox.net cc: pgsql-jdbc@postgresql.org Subject: Re: Column is of type date but expression is of type text In-Reply-To: <1e11c2271002171814i704d31f4oca1d819dc5a02103@mail.gmail.com> Message-ID: References: <1e11c2271002171814i704d31f4oca1d819dc5a02103@mail.gmail.com> User-Agent: Alpine 2.00 (BSO 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.541 tagged_above=-10 required=5 tests=AWL=0.058, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/30 X-Sequence-Number: 20317 On Wed, 17 Feb 2010, list_usr@spacebox.net wrote: > I'm trying to call a stored procedure from a Java app; the stored procedure > just makes an insert on a table and returns true or false. It seems there's > a problem when a java.sql.Date type parameter is passed from Java to the > PostgreSQL stored procedure, and then to the insert: LOG: execute : > select * from athlete.create_athlete($1,$2,$3,$4,$5,$6,$7) as result DETAIL: > parameters: $1 = '', $2 = 'foo@bar.com', $3 = 'Joe', $4 = 'Blow', $5 = > 'foobar', $6 = 'M', $7 = '1979-03-22 -04:00:00' ERROR: column "dob" is of > type date but expression is of type text at character 122 HINT: You will > need to rewrite or cast the expression. QUERY: INSERT INTO athlete.athlete > (email, first_name, last_name, password, gender, dob) VALUES ( $1 , $2 , $3 > , $4 , $5 , $6 ) CONTEXT: PL/pgSQL function "create_athlete" line 2 at SQL > statement STATEMENT: select * from > athlete.create_athlete($1,$2,$3,$4,$5,$6,$7) as result The Java code, in > brief: registerQuery = "{? = call athlete.create_athlete(?,?,?,?,?,?)}"; > .... CallableStatement cs = conn.prepareCall(registerQuery); > cs.registerOutParameter(1, Types.BOOLEAN); cs.setString(2, email); .... > createAthlete.setDate(7, birthdate); // birthdate is of type java.sql.Date > I've asked elsewhere, and it seems my Java code is correct for a stored > procedure that returns a single value. However I'm still uncertain because > the logs show 7 parameters in the call to create_athlete() when there should > only be 6 - if parameters $1-$6 in the call to create_athlete() are the > parameters passed to the insert statement, then the dob parameter would be > mismatched with the gender parameter. Are parameters $2-$7 actually passed > to the insert? If yes, where am I going wrong? Without seeing what your function is doing it's tough to tell where things are going wrong. Perhaps you've switched some parameters around from the function arguments to the insert call? The JDBC driver rearranges the output parameter to be in the argument list for it's own internal convenience. This is OK and doesn't affect the parameter numbering or the calling of the function. Kris Jurka