pg 事务 存储过程_存储过程是否在Postgres中的数据库事务中运行?

严格来说,Postgres目前(不包括版本10)具有ANSI标准中定义的“存储过程”.一切都是通过“函数”完成的,它们提供了与其他RDBMS提供的存储过程相同的功能(和更多).主要区别在于交易处理.

Postgres 11终于推出了真正的stored procedures:

Functions在Postgres中是原子的,并且在自己的事务中自动运行,除非在外部事务中调用.它们总是在单个事务中运行,并且完全成功或失败.因此,无法在函数内开始或提交事务.并且不允许在事务块中运行的VACUUM或CREATE INDEX CONCURRENTLY等命令.

Functions and trigger procedures are always executed within a

transaction established by an outer query — they cannot start or

commit that transaction, since there would be no context for them to

execute in. However, a block containing an EXCEPTION clause

effectively forms a subtransaction that can be rolled back without

affecting the outer transaction.

By default, any error occurring in a PL/pgSQL function aborts

execution of the function, and indeed of the surrounding transaction

as well. You can trap errors and recover from them by using a BEGIN

block with an EXCEPTION clause.

有特殊例外,包括但不限于:

Important: Some PostgreSQL data types and functions have special rules

regarding transactional behavior. In particular, changes made to a

sequence (and therefore the counter of a column declared using serial)

are immediately visible to all other transactions and are not rolled

back if the transaction that made the changes aborts.

>准备好的陈述

> dblink调用(或类似)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值