PostgreSQL ODBC驱动程序和光标问题
在我的应用程序中,我使用光标从存储过程中接收数据集。 但是我有一个错误:
ERROR: invalid transaction termination
CONTEXT: PL/pgSQL function inline_code_block line 6 at COMMIT
SQL state: 2D000
如果未设置自动加入选项,则此错误会增加。 在DBEAVER IDE中,如果自动加入打开,我没有错误。 在PGADMIN 4中,我以任何方式有错误(自动加入已打开或关闭)。
在我的应用中,我使用ODBC驱动程序进行连接。 如何在驱动程序设置中设置自动加入选项?
测试代码Bellow:
create table test_table (spid int);
insert into test_table
select 1;
insert into test_table
select pg_backend_pid();
do $$
declare
var_ImplicitResultSet refcursor := 'var_implicitresultset';
begin
delete from test_table where spid = pg_backend_pid();
commit;
open var_ImplicitResultSet FOR SELECT spid from test_table where spid <> pg_backend_pid();
END
$$;
fetch all from var_implicitresultset;
还是有其他方法可以从存储过程中获取数据集? PS我正在调整旧应用程序,因此我需要学习如何从过程中返回数据集,
感谢您的答案!
In my app I use cursor to recieve dataset from stored procedure.
But I have an error:
ERROR: invalid transaction termination
CONTEXT: PL/pgSQL function inline_code_block line 6 at COMMIT
SQL state: 2D000
This error raise in case when AutoCommit option is not set.
In DBeaver IDE if autocommit is ON, I have no error.
In pgAdmin 4 this I have error any way (autocommit is on OR is OFF).
In my app I use ODBC driver to connect.
How can I set autocommit option in driver settings?
Test code bellow:
create table test_table (spid int);
insert into test_table
select 1;
insert into test_table
select pg_backend_pid();
do $
declare
var_ImplicitResultSet refcursor := 'var_implicitresultset';
begin
delete from test_table where spid = pg_backend_pid();
commit;
open var_ImplicitResultSet FOR SELECT spid from test_table where spid <> pg_backend_pid();
END
$;
fetch all from var_implicitresultset;
Or is there another way to get the dataset from the stored procedure?
P.S. I'm adapting an old application so I need to learn how to return datasets from within procedures
Thanks for answer!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论