AFTER INSERT 在单独的事务中触发? [英] AFTER INSERT trigger in separate transaction?

查看:38
本文介绍了AFTER INSERT 在单独的事务中触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AFTER INSERT 触发器(用 pl/PGsql 编写的函数)是否会在与原始插入不同的事务中触发?

Will an AFTER INSERT trigger (function written in pl/PGsql) fire in a separate transaction than the original insert?

我担心的是触发器是否会遇到某种异常.
是否可以在不影响原始插入的情况下回滚触发器?

What I'm concerned about is if the trigger experiences an exception of some kind.
Can the trigger be rolled back without the original insert being affected?

推荐答案

所有 PostgreSQL 触发器都在与触发它们的事务相同的事务中执行.

All PostgreSQL triggers execute in the same transaction as the transaction that has triggered them.

编辑:您还可以使用 LISTEN + NOTIFY 将消息从触发器发送到在事务之外执行的代码.在这种情况下,消息只会在成功提交时传递.侦听器中的错误不会回滚触发事务.

Edit: You can also use LISTEN + NOTIFY to send a message from your trigger to a code that executes outside of the transaction. In that case, the message will only be delivered at the point of a successful commit. Errors in listeners will not roll back the triggering transaction.

这篇关于AFTER INSERT 在单独的事务中触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆