LISTEN 中文man頁(yè)面
NAME
LISTEN - 監(jiān)聽一個(gè)通知
SYNOPSIS
LISTEN name
DESCRIPTION 描述
LISTEN 將當(dāng)前會(huì)話注冊(cè)為通知條件 name
當(dāng)執(zhí)行了命令 NOTIFY name 后,不管是此會(huì)話還是其他聯(lián)接到同一數(shù)據(jù)庫(kù)的會(huì)話執(zhí)行的, 所有正在監(jiān)聽此通知條件的會(huì)話都將收到通知, 并且接下來(lái)每個(gè)會(huì)話將通知與其相連的前端應(yīng)用.請(qǐng)參考 NOTIFY 獲取更多信息.
使用 UNLISTEN 命令,可以將一個(gè)會(huì)話內(nèi)已注冊(cè)的通知條件刪除. 同樣,會(huì)話退出時(shí)自動(dòng)刪除該會(huì)話正在監(jiān)聽的已注冊(cè)通知條件.
前端應(yīng)用檢測(cè)通知事件的方法取決于 PostgreSQL 應(yīng)用使用的編程接口. 如果使用基本的libpq庫(kù), 應(yīng)用將 LISTEN 當(dāng)作普通 SQL 命令使用,而且必須周期地調(diào)用 PQnotifies 過程來(lái)檢測(cè)是否有通知到達(dá). 其他像libpgtcl接口提供了更高級(jí)的控制通知事件的方法;實(shí)際上, 使用libpgtcl,應(yīng)用程序員不應(yīng)該直接使用 LISTEN 或 UNLISTEN. 請(qǐng)參考你使用的接口的文檔獲取更多細(xì)節(jié).
NOTIFY [notify(7)] 的手冊(cè)頁(yè)包含更廣泛的關(guān)于 LISTEN 和 NOTIFY 的使用的討論.
PARAMETERS 參數(shù)
- name
通知條件名 (任何標(biāo)識(shí)符)。
EXAMPLES 例子
在 psql 里配制和執(zhí)行一個(gè)監(jiān)聽/通知序列:
LISTEN virtual; NOTIFY virtual; Asynchronous notification "virtual" received from server process with PID 8448.
COMPATIBILITY 兼容性
在 SQL 標(biāo)準(zhǔn)里沒有 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)]