Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 9b6cc37ce608401d44f6535a0c7cb777 > files > 984

postgresql11-docs-11.5-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>F.39. tcn</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="tablefunc.html" title="F.38. tablefunc" /><link rel="next" href="test-decoding.html" title="F.40. test_decoding" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">F.39. tcn</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="tablefunc.html" title="F.38. tablefunc">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 11.5 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="test-decoding.html" title="F.40. test_decoding">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="TCN"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.39. tcn</h2></div></div></div><a id="id-1.11.7.48.2" class="indexterm"></a><a id="id-1.11.7.48.3" class="indexterm"></a><p>
  The <code class="filename">tcn</code> module provides a trigger function that notifies
  listeners of changes to any table on which it is attached.  It must be
  used as an <code class="literal">AFTER</code> trigger <code class="literal">FOR EACH ROW</code>.
 </p><p>
  Only one parameter may be supplied to the function in a
  <code class="literal">CREATE TRIGGER</code> statement, and that is optional.  If supplied
  it will be used for the channel name for the notifications.  If omitted
  <code class="literal">tcn</code> will be used for the channel name.
 </p><p>
  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.  Embedded quotes are doubled.
 </p><p>
  A brief example of using the extension follows.

</p><pre class="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
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.
</pre><p>
 </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tablefunc.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="test-decoding.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.38. tablefunc </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> F.40. test_decoding</td></tr></table></div></body></html>