[Pljava-dev] Calling pl/pgsql functions from pl/java?

From: lucas at mcsnw(dot)com (Lucas Madar)
To:
Subject: [Pljava-dev] Calling pl/pgsql functions from pl/java?
Date: 2007-12-20 08:52:15
Message-ID: C9C052B6-2121-49CF-AED6-58FB5BC84B08@mcsnw.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

I finally had time to go back and look at this, and it appears that
this is unique to PL/Java.

When Statement.execute(query) is called, the statement is not actually
executed by that command if it is a select query. This behavior is in
SPIStatement.executePlan... If isCursorPlan() returns true, a cursor
is opened for the query instead of executing it; nothing is done until
the resultset is acquired and *used*.

This works, it's just kind of kludgy, especially for functions that
don't actually return a useful value.

stmt.execute("SELECT mangle_user(5)"); // works with jdbc postgresql
driver
ResultSet res = stmt.getResultSet(); res.next(); res.close(); //
kludge to get calls to work with plpgsql

Perhaps this should be documented somewhere?

Thanks,
Lucas Madar

On Dec 10, 2007, at 7:01 PM, Jeffrey Lyon wrote:

> That's probably a question for the PostgreSQL guys, but it looks
> like the function isn't actually being called until the moment that
> the value is needed.
>
> J
>
> On Dec 10, 2007, at 9:31 PM, Lucas Madar wrote:
>
>> Oops. That was a stupid mistake in my dummy code. In the much more
>> complicated code, I've run into an interesting observation.
>>
>> If I call a function with select function(arg1, arg2) and then
>> ignore any returned result set, the function doesn't even get
>> executed.
>> If the function doesn't have a return (a null), there's nothing I
>> can do.
>>
>> If the function, however, returns something and I process its
>> resultset, the function is executed.
>>

In response to

Browse pljava-dev by date

  From Date Subject
Next Message Lucas Madar 2008-01-05 09:57:44 [Pljava-dev] ResultSetHandle and TupleDesc reference leak?
Previous Message Galinat, Alice 2007-12-12 19:52:11 [Pljava-dev] (no subject)