NAME
LISTEN - 监听一个通知
SYNOPSIS
LISTEN name
DESCRIPTION 描述
LISTEN 将当前会话注册为通知条件 name
当执行了命令 NOTIFY name 后,不管是此会话还是其他联接到同一数据库的会话执行的, 所有正在监听此通知条件的会话都将收到通知, 并且接下来每个会话将通知与其相连的前端应用.请参考 NOTIFY 获取更多信息.
使用 UNLISTEN 命令,可以将一个会话内已注册的通知条件删除. 同样,会话退出时自动删除该会话正在监听的已注册通知条件.
前端应用检测通知事件的方法取决于 PostgreSQL 应用使用的编程接口. 如果使用基本的libpq库, 应用将 LISTEN 当作普通 SQL 命令使用,而且必须周期地调用 PQnotifies 过程来检测是否有通知到达. 其他像libpgtcl接口提供了更高级的控制通知事件的方法;实际上, 使用libpgtcl,应用程序员不应该直接使用 LISTEN 或 UNLISTEN. 请参考你使用的接口的文档获取更多细节.
NOTIFY [notify(7)] 的手册页包含更广泛的关于 LISTEN 和 NOTIFY 的使用的讨论.
PARAMETERS 参数
- name
通知条件名 (任何标识符)。
EXAMPLES 例子
在 psql 里配制和执行一个监听/通知序列:
LISTEN virtual; NOTIFY virtual; Asynchronous notification "virtual" received from server process with PID 8448.
COMPATIBILITY 兼容性
在 SQL 标准里没有 LISTEN
SEE ALSO 参见
NOTIFY [notify(7)], UNLISTEN [unlisten(l)]
#p#
NAME
LISTEN - listen for a notification
SYNOPSIS
LISTEN name
DESCRIPTION
LISTEN registers the current session as a listener on the notification condition name. If the current session is already registered as a listener for this notification condition, nothing is done.
Whenever the command NOTIFY name is invoked, either by this session or another one connected to the same database, all the sessions currently listening on that notification condition are notified, and each will in turn notify its connected client application. See the discussion of NOTIFY for more information.
A session can be unregistered for a given notify condition with the UNLISTEN command. A session's listen registrations are automatically cleared when the session ends.
The method a client application must use to detect notification events depends on which PostgreSQL application programming interface it uses. With the libpq library, the application issues LISTEN as an ordinary SQL command, and then must periodically call the function PQnotifies to find out whether any notification events have been received. Other interfaces such as libpgtcl provide higher-level methods for handling notify events; indeed, with libpgtcl the application programmer should not even issue LISTEN or UNLISTEN directly. See the documentation for the interface you are using for more details.
NOTIFY [notify(7)] contains a more extensive discussion of the use of LISTEN and NOTIFY.
PARAMETERS
- name
- Name of a notify condition (any identifier).
EXAMPLES
Configure and execute a listen/notify sequence from psql:
LISTEN virtual; NOTIFY virtual; Asynchronous notification "virtual" received from server process with PID 8448.
COMPATIBILITY
There is no LISTEN statement in the SQL standard.
SEE ALSO
NOTIFY [notify(7)], UNLISTEN [unlisten(l)]