如何使用 pg 从 postgres 存储过程或函数中检索结果集

问题描述

嗨,我正在开发一个使用 postgres 的 Web 应用程序,其中一些 sql 位于存储过程/函数中。如果一个函数返回一个游标,我们如何在 nodejs 中检索和处理结果集?我正在使用 pg (node-postgres)。以下是我想从 nodejs 代码调用的测试过程的代码。

drop table if exists tmp;
create table tmp
(
  x integer
);
drop function if exists t1;

create or replace function t1( p_value integer)
returns refcursor
language plpgsql
as $$
declare
  ref refcursor;
begin
  --insert into tmp(x) values(p_value);
  open ref for select x from tmp;
  return ref;
end
$$;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)