2012-01-20 05:15:15 +01:00
|
|
|
<!-- doc/src/sgml/tcn.sgml -->
|
|
|
|
|
|
|
|
<sect1 id="tcn" xreflabel="tcn">
|
|
|
|
<title>tcn</title>
|
|
|
|
|
|
|
|
<indexterm zone="tcn">
|
|
|
|
<primary>tcn</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="tcn">
|
|
|
|
<primary>triggered_change_notification</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <filename>tcn</filename> module provides a trigger function that notifies
|
2012-01-20 05:15:15 +01:00
|
|
|
listeners of changes to any table on which it is attached. It must be
|
2017-10-09 03:44:17 +02:00
|
|
|
used as an <literal>AFTER</literal> trigger <literal>FOR EACH ROW</literal>.
|
2012-01-20 05:15:15 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2012-01-22 22:34:28 +01:00
|
|
|
Only one parameter may be supplied to the function in a
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>CREATE TRIGGER</literal> statement, and that is optional. If supplied
|
2012-01-20 05:15:15 +01:00
|
|
|
it will be used for the channel name for the notifications. If omitted
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>tcn</literal> will be used for the channel name.
|
2012-01-20 05:15:15 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
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
|
2012-04-12 16:43:39 +02:00
|
|
|
single quotes. Embedded quotes are doubled.
|
2012-01-20 05:15:15 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
A brief example of using the extension follows.
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
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
|
2018-08-15 23:08:34 +02:00
|
|
|
test-# for each row execute function triggered_change_notification();
|
2012-01-20 05:15:15 +01:00
|
|
|
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.
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect1>
|