0

我想批量调用一个存储的函数。我正在使用 JOOQ 3.7.3 和 PostgreSQL 9.5。我曾尝试select [function call]批量使用语句,但它会引发以下异常PSQLException: A result was returned when none was expected

 // exemplary 'select [function call]'
 context.batch(context.select(Routines.foo(someParam))).execute();

我发现没有其他方法可以用 JOOQ 批量调用存储的函数。我知道原始 JDBC 和CallableStatement是可能的,所以我假设 JOOQ 也应该是可能的。

JOOQ 可以批量调用存储的函数吗?如果是,该怎么做?

存储函数签名:

create function foo(param1 int, param2 int) returns boolean as $$ ... $$ language plpgsql
4

1 回答 1

1

select [function call]最新的 9.4.1208 postgres jdbc 驱动程序支持该语法。我使用的是 9.4.1205 版本。

如果您使用最新的 (9.4.1208) jdbc 驱动程序,如果存储的函数返回某个值,则可以使用以下语法:

Query query1 = context.select(Routines.foo(someParam));
Query query2 = context.select(Routines.foo(someParam));
context.batch(query1, query2).execute();

如果存储的函数返回void,您可以使用:

Foo foo1 = new Foo(); foo1.setParam(someParam);
Foo foo2 = new Foo(); foo2.setParam(someParam);
context.batch(context.select(foo1.asField()), context.select(foo2.asField())).execute();
于 2016-03-23T11:29:33.593 回答