Commit, savepoint, rollback to in PostgreSQL?

前端 未结 2 1571
心在旅途
心在旅途 2020-12-16 03:38

Can someone please explain to me why does COMMIT in this function returns EXCEPTION ?

DECLARE
  XNar CURSOR (forDATE Varchar) IS 
   SELECT NARUCENO, ISPORUK         


        
相关标签:
2条回答
  • 2020-12-16 04:16

    You can't commit in a plpgsql stored function/procedure using plpgsql as Frank Heikens answered. You can however work around this issue by using dblink(http://www.postgresql.org/docs/9.0/interactive/contrib-dblink-connect.html) or another store procedure language such as plperl(untrusted). Check out this link where this talked about.

    http://postgresql.1045698.n5.nabble.com/Re-GENERAL-Transactions-within-a-function-body-td1992810.html

    The high level is you open a new connection using one of these methods and issue a separate transaction on that connection. Works for most cases not ideal because you are opening a new connection, but may work fine for most use cases.

    0 讨论(0)
  • 2020-12-16 04:24

    You can't use COMMIT in a stored procedure, the entire procedure is a transaction of it's own.

    0 讨论(0)
提交回复
热议问题