From: lucas at mcsnw.com (Lucas Madar) Date: Thu, 20 Dec 2007 00:52:15 -0800 Subject: [Pljava-dev] Calling pl/pgsql functions from pl/java? In-Reply-To: References: <475DE7E2.3000506@mcsnw.com> <141A53EE-DEE3-4C80-B4EF-F5A888F6F568@mac.com> <475DF66A.4030400@mcsnw.com> Message-ID: 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. >>