PostgreSQL ODBC驱动程序和光标问题

发布于 2025-01-21 07:15:20 字数 902 浏览 4 评论 0原文

在我的应用程序中,我使用光标从存储过程中接收数据集。 但是我有一个错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文