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

Lucas Madar lucas at mcsnw.com
Thu Dec 20 08:52:15 UTC 2007


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.
>>



More information about the Pljava-dev mailing list