我在执行在jooq中获取和返回postgresrefcursor
的函数时遇到了一些问题。我不知道如何实例化ref
,这是Result<Record>
以及如何循环访问我应该从我想要执行的函数中获得的记录。
假设我在 postgres (postgres 9.5( 中有一个以下函数:
create or replace function foo_cursor(name character varying, ref refcursor)
returns refcursor
as $func$
begin
open ref for
select id, first_name, last_name
from students
where first_name = name;
return ref;
end
$func$
language plpgsql;
在帖子中,我像这样执行:
begin;
select foo_cursor('Konrad', 'my_cursor');
fetch all in "my_cursor";
commit;
该函数必须保持不变 - 它返回refcursor
并获取refcursor
。
我想在jOOQ中执行它:
Routines.fooCursor(configuration, "Konrad", ____);
但我不知道在____
里放什么,这需要Result<Record>
.我尝试了类似的东西:
Result<Record> records = DSL.using(configuration).newResult();
但它也没有用。
>jOOQ支持PostgreSQL中的refcursor
结果类型(或OUT
参数(,但不支持IN
参数类型,这确实有点怪癖,因为它假装是标识符的伪类型。如果可以将函数重载到:
create or replace function foo_cursor(name character varying)
returns refcursor
as $func$
declare
ref refcursor;
begin
open ref for
select id, first_name, last_name
from students
where first_name = name;
return ref;
end
$func$
language plpgsql;
然后,jOOQ 将能够调用该函数。不需要 jOOQ(或者您使用 jOOQ 时(来定义生成的游标名称。
但是,您可能需要在事务中运行函数调用。