pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mario Splivalo <mario.splivalo@mobart.hr>
To: pgsql-jdbc@postgresql.org
Subject: Calling functions with table-based-type parametars
Date: Fri, 23 Feb 2007 16:59:34 +0100
Message-ID: <1172246374.23787.25.camel@localhost.localdomain> (raw)

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




view thread (7+ messages)  latest in thread

Message-ID: <1172246374.23787.25.camel@localhost.localdomain>
Permalink:  ../1172246374.23787.25.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1172246374.23787.25.camel@localhost.localdomain

 · 

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: mario.splivalo@mobart.hr
  Subject: Re: Calling functions with table-based-type parametars
  In-Reply-To: <1172246374.23787.25.camel@localhost.localdomain>
  References: <1172246374.23787.25.camel@localhost.localdomain>

* 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