答案 0 :(得分:3)
这是一个有趣的问题。也许文档不清楚,但是以我的经验,重复的通知仅在子事务中发送。
不仅仅是在这里猜测,让我们打开PostgreSQL源代码。通知功能具有test of duplicates:
/* no point in making duplicate entries in the list ... */
if (AsyncExistsPendingNotify(channel, payload))
return;
好的,但是它不能解释重复的可能性。因此,我们可以继续检查AsyncExistsPendingNotify函数。在此函数内的某个地方,我们在注释中找到了答案:
/*
* As we are not checking our parents' lists, we can still get duplicates
* in combination with subtransactions, like in:
*
* begin;
* notify foo '1';
* savepoint foo;
* notify foo '1';
* commit;
*/
就是这样。使用子交易时,我们可以有重复的通知。该文档可能更清晰,但是PostgreSQL的人们可能是故意这样做的。因此,我可以得出结论,在这种情况下,避免重复不是严格的要求。