tcn
模組提供了一個觸發器函式,用於通知在該觸發器函式上附加的任何表內容更改的監聽器。它必須用作 AFTER
觸發器 FOR EACH ROW
。
此模組被認為是“受信任的”,這意味著非超級使用者也可以在其擁有的資料庫上安裝它,前提是他們具有 CREATE
許可權。
在 CREATE TRIGGER
語句中,該函式最多隻能提供一個引數,並且該引數是可選的。如果提供了引數,則它將用於通知的頻道名稱。如果省略,則 tcn
將用作頻道名稱。
通知的有效載荷包含表名、指示執行何種操作的字母以及主鍵列的列名/值對。每個部分之間用逗號分隔。為了方便使用正則表示式進行解析,表名和列名始終用雙引號括起來,資料值始終用單引號括起來。嵌入的引號會加倍。
下面是一個使用該擴充套件的簡短示例。
test=# create table tcndata test-# ( test(# a int not null, test(# b date not null, test(# c text, test(# primary key (a, b) test(# ); CREATE TABLE test=# create trigger tcndata_tcn_trigger test-# after insert or update or delete on tcndata test-# for each row execute function triggered_change_notification(); CREATE TRIGGER test=# listen tcn; LISTEN test=# insert into tcndata values (1, date '2012-12-22', 'one'), test-# (1, date '2012-12-23', 'another'), test-# (2, date '2012-12-23', 'two'); INSERT 0 3 Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-22'" received from server process with PID 22770. Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-23'" received from server process with PID 22770. Asynchronous notification "tcn" with payload ""tcndata",I,"a"='2',"b"='2012-12-23'" received from server process with PID 22770. test=# update tcndata set c = 'uno' where a = 1; UPDATE 2 Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-22'" received from server process with PID 22770. Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-23'" received from server process with PID 22770. test=# delete from tcndata where a = 1 and b = date '2012-12-22'; DELETE 1 Asynchronous notification "tcn" with payload ""tcndata",D,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
如果您在文件中發現任何不正確之處,與您在使用特定功能時的體驗不符,或者需要進一步澄清,請使用 此表單 來報告文件問題。