From 6e3323d41dc45e93700a3420fd27ca05db6a64a7 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Thu, 19 Jan 2012 23:15:15 -0500 Subject: Triggered change notifications. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kevin Grittner, reviewed (in earlier versions) by Álvaro Herrera --- doc/src/sgml/contrib.sgml | 1 + doc/src/sgml/filelist.sgml | 1 + doc/src/sgml/tcn.sgml | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 doc/src/sgml/tcn.sgml (limited to 'doc/src') diff --git a/doc/src/sgml/contrib.sgml b/doc/src/sgml/contrib.sgml index adf09ca872d..d4da4eec87d 100644 --- a/doc/src/sgml/contrib.sgml +++ b/doc/src/sgml/contrib.sgml @@ -128,6 +128,7 @@ CREATE EXTENSION module_name FROM unpackaged; &contrib-spi; &sslinfo; &tablefunc; + &tcn; &test-parser; &tsearch2; &unaccent; diff --git a/doc/src/sgml/filelist.sgml b/doc/src/sgml/filelist.sgml index b96dd656ad3..b5d3c6d4fce 100644 --- a/doc/src/sgml/filelist.sgml +++ b/doc/src/sgml/filelist.sgml @@ -136,6 +136,7 @@ + diff --git a/doc/src/sgml/tcn.sgml b/doc/src/sgml/tcn.sgml new file mode 100644 index 00000000000..af830dfffec --- /dev/null +++ b/doc/src/sgml/tcn.sgml @@ -0,0 +1,72 @@ + + + + tcn + + + tcn + + + + triggered_change_notification + + + + The tcn module provides a trigger function that notifies + listeners of changes to any table on which it is attached. It must be + used as an AFTER trigger FOR EACH ROW. + + + + Only one parameter may be suupplied to the function in a + CREATE TRIGGER statement, and that is optional. If supplied + it will be used for the channel name for the notifications. If omitted + tcn will be used for the channel name. + + + + The payload of the notifications consists of the table name, a letter to + indicate which type of operation was performed, and column name/value pairs + for primary key columns. Each part is separated from the next by a comma. + For ease of parsing using regular expressions, table and column names are + always wrapped in double quotes, and data values are always wrapped in + single quotes. Embeded quotes are doubled. + + + + A brief example of using the extension follows. + + +test=# create table tcndata +test-# ( +test(# a int not null, +test(# b date not null, +test(# c text, +test(# primary key (a, b) +test(# ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "tcndata_pkey" for table "tcndata" +CREATE TABLE +test=# create trigger tcndata_tcn_trigger +test-# after insert or update or delete on tcndata +test-# for each row execute procedure 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. + + + + -- cgit v1.2.3