pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: list_usr@spacebox.net
To: Kris Jurka <books@ejurka.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Column is of type date but expression is of type text
Date: Thu, 18 Feb 2010 16:27:12 -0500
Message-ID: <1e11c2271002181327g52545a34u6a91c5b17cd1fdfd@mail.gmail.com> (raw)
In-Reply-To: <alpine.BSO.2.00.1002180017340.30823@leary.csoft.net>
References: <1e11c2271002171814i704d31f4oca1d819dc5a02103@mail.gmail.com>
	<alpine.BSO.2.00.1002180017340.30823@leary.csoft.net>

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;
    	
    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 <books@ejurka.com> 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 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 <unnamed>:
>> 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
>



view thread (12+ messages)  latest in thread

Message-ID: <1e11c2271002181327g52545a34u6a91c5b17cd1fdfd@mail.gmail.com>
Permalink:  ../1e11c2271002181327g52545a34u6a91c5b17cd1fdfd@mail.gmail.com/
Also on:    postgresql.org/message-id/1e11c2271002181327g52545a34u6a91c5b17cd1fdfd@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: list_usr@spacebox.net, books@ejurka.com
  Subject: Re: Column is of type date but expression is of type text
  In-Reply-To: <1e11c2271002181327g52545a34u6a91c5b17cd1fdfd@mail.gmail.com>
  References: <1e11c2271002171814i704d31f4oca1d819dc5a02103@mail.gmail.com> <alpine.BSO.2.00.1002180017340.30823@leary.csoft.net> <1e11c2271002181327g52545a34u6a91c5b17cd1fdfd@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox