Calling functions with table-based-type parametars

From: Mario Splivalo <mario(dot)splivalo(at)mobart(dot)hr>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Calling functions with table-based-type parametars
Date: 2007-02-23 15:59:34
Message-ID: 1172246374.23787.25.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello again :)

I have a PSQL function that accepts table-based-type as parametar:

CREATE TABLE t1(c1 int4, c2 varchar);

CREATE FUNCTION f1(t1) RETURNS VOID
AS 'BEGIN RETURN END;' LANGUAGE 'plpgsql';

Now, when I call this function from another function (or from psql, for
instance), i need to do it like this:

select f1(ROW(1, 'sometext'));

How do I do that from JDBC? Usualy I did it like this:

callStatement = conn.getCallStatement("{call f1(?, ?)}");
callStatement.setInt(1, 1);
callStatement.setString(2, 'sometext');
callStatement.execute();
ResultSet rs = callStatement.getResultSet();

But when I do it like that I get 'function does not exists', which is
logical (my function accepts one, not two parametars).

I have found out that I can use createstatement like this:

Connection c = DriverManager.getConnection('jdbc://...');
s = c.createStatement();
ResultSet rs = s.executeQuery("select f1(ROW(1, 'sometext'));");

Now, as I understand, first snippet uses prepared statements, and second
one doesnt. Can I have prepared statements and still pass ROW as
function parametar? Or JDBC does not support that?

Mike

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tore Halset 2007-02-23 17:31:38 Re: invalid byte sequence for encoding "UTF8": 0x00
Previous Message Blakely, Jerel (Mission Systems) 2007-02-23 01:08:30 Re: Problem with jdbc connection behavior