Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id A5FF2633222 for ; Thu, 18 Feb 2010 17:27:24 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 42189-06 for ; Thu, 18 Feb 2010 21:27:13 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-px0-f180.google.com (mail-px0-f180.google.com [209.85.216.180]) by mail.postgresql.org (Postfix) with ESMTP id 02F4B632D41 for ; Thu, 18 Feb 2010 17:27:13 -0400 (AST) Received: by pxi10 with SMTP id 10so2162163pxi.13 for ; Thu, 18 Feb 2010 13:27:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=i6SjJhS0Tey7D8iupA9pQdTO7kw1su4FD7Jp9g4GQvI=; b=IvSrMCZIRwxpBmgtywqinzmEbNr6NdGsbAgmMaq34JYjjCgjmxHcItpOfU1/x7MdIG Jhy9wbFZ3jsZOERd+NCciiyZqlf/8GpgCdgiwTH734IWnYLuntMGPirSmN568yEXASze 3vO+rsMrN+Ut5NFBiBfCoMyOjNC5j1I3blB54= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=gKmvpWKeCJOLTfNkwB6Ogzz52rfTXgWYfRh9jFMgrXyAclwxJCCMy3l9+lMdVyl/bp IXIGMBz6vUbWDS32JF8hv/sULJSZhiBEEpxtt6OVTs7jhbjLkfrwS9XbKnlaq3NzjKRQ sM+SJ2fXbMtRW//pE9gwI7FoNRjX7K5uNqULI= MIME-Version: 1.0 Received: by 10.142.59.21 with SMTP id h21mr1275273wfa.182.1266528432285; Thu, 18 Feb 2010 13:27:12 -0800 (PST) In-Reply-To: References: <1e11c2271002171814i704d31f4oca1d819dc5a02103@mail.gmail.com> Date: Thu, 18 Feb 2010 16:27:12 -0500 X-Google-Sender-Auth: 9ea73aa75f369f1e Message-ID: <1e11c2271002181327g52545a34u6a91c5b17cd1fdfd@mail.gmail.com> Subject: Re: Column is of type date but expression is of type text From: list_usr@spacebox.net To: Kris Jurka Cc: pgsql-jdbc@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/32 X-Sequence-Number: 20319 Here is the stored procedure in question: CREATE FUNCTION athlete_add(IN new_email TEXT, IN fname TEXT, IN lname TEXT, IN pw TEXT, IN sex TEXT, IN bdate DATE) RETURNS BOOLEAN AS $$ BEGIN INSERT INTO athlete (email, first_name, last_name, password, gender, dob) VALUES (new_email, fname, lname, pw, sex, bdate); IF FOUND THEN RETURN TRUE; END IF; =09 RETURN FALSE; END; $$ LANGUAGE plpgsql; As an aside, how do most people name their IN parameters so as not to have them conflict with actual column names? Thanks, -- Matt On Thu, Feb 18, 2010 at 12:34 AM, Kris Jurka wrote: > > > On Wed, 17 Feb 2010, list_usr@spacebox.net wrote: > >> I'm trying to call a stored procedure from a Java app; the stored proced= ure >> just makes an insert on a table and returns true or false. It seems ther= e'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 DET= AIL: >> parameters: $1 =3D '', $2 =3D 'foo@bar.com', $3 =3D 'Joe', $4 =3D 'Blow'= , $5 =3D >> 'foobar', $6 =3D 'M', $7 =3D '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.athle= te >> (email, first_name, last_name, password, gender, dob) VALUES ( $1 , $2 ,= $3 >> , $4 , $5 , $6 ) CONTEXT: PL/pgSQL function "create_athlete" line 2 at S= QL >> statement STATEMENT: select * from >> athlete.create_athlete($1,$2,$3,$4,$5,$6,$7) as result The Java code, in >> brief: registerQuery =3D "{? =3D call athlete.create_athlete(?,?,?,?,?,?= )}"; >> .... CallableStatement cs =3D conn.prepareCall(registerQuery); >> cs.registerOutParameter(1, Types.BOOLEAN); cs.setString(2, email); .... >> createAthlete.setDate(7, birthdate); // birthdate is of type java.sql.Da= te >> 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 becau= se >> the logs show 7 parameters in the call to create_athlete() when there sh= ould >> 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 pass= ed >> to the insert? If yes, where am I going wrong? > > Without seeing what your function is doing it's tough to tell where thing= s are going wrong. =A0Perhaps you've switched some parameters around from t= he function arguments to the insert call? =A0The JDBC driver rearranges the= output parameter to be in the argument list for it's own internal convenie= nce. =A0This is OK and doesn't affect the parameter numbering or the callin= g of the function. > > Kris Jurka >