小编Dam*_*yer的帖子

无法在 PostgreSQL 11.5 中创建 COMMIT 过程

我正在尝试学习 PostgreSQL 存储过程。具体在 PSQL 中创建以下过程。

CREATE OR REPLACE PROCEDURE BUILD_AND_POPULATE(INOUT cresults refcursor) 
    LANGUAGE PLPGSQL 
    AS $$
    BEGIN
        BEGIN; -- I've tried removing this but the behaviour is the same
        cresults:= 'cur';
        DROP TABLE IF EXISTS procsampledata;
        CREATE TABLE procsampledata as select x,1 as c2,2 as c3, md5(random()::text) from generate_series(1,10) x;  
        COMMIT;
        OPEN cresults FOR SELECT * FROM procsampledata;  
    END;
$$;
Run Code Online (Sandbox Code Playgroud)

然后我像这样执行它,但收到一个错误:

postgres=# call build_and_populate(null);
ERROR:  invalid transaction termination
CONTEXT:  PL/pgSQL function build_and_populate(refcursor) line 6 at COMMIT
Run Code Online (Sandbox Code Playgroud)

我试过将 AUTOCOMMIT 设置为打开和关闭。

这是我的 …

postgresql plpgsql

3
推荐指数
1
解决办法
7492
查看次数

标签 统计

plpgsql ×1

postgresql ×1