gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
4.7KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!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 V1.79.1" /><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 12.4 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>
  3. The <code class="filename">tcn</code> module provides a trigger function that notifies
  4. listeners of changes to any table on which it is attached. It must be
  5. used as an <code class="literal">AFTER</code> trigger <code class="literal">FOR EACH ROW</code>.
  6. </p><p>
  7. Only one parameter may be supplied to the function in a
  8. <code class="literal">CREATE TRIGGER</code> statement, and that is optional. If supplied
  9. it will be used for the channel name for the notifications. If omitted
  10. <code class="literal">tcn</code> will be used for the channel name.
  11. </p><p>
  12. The payload of the notifications consists of the table name, a letter to
  13. indicate which type of operation was performed, and column name/value pairs
  14. for primary key columns. Each part is separated from the next by a comma.
  15. For ease of parsing using regular expressions, table and column names are
  16. always wrapped in double quotes, and data values are always wrapped in
  17. single quotes. Embedded quotes are doubled.
  18. </p><p>
  19. A brief example of using the extension follows.
  20. </p><pre class="programlisting">
  21. test=# create table tcndata
  22. test-# (
  23. test(# a int not null,
  24. test(# b date not null,
  25. test(# c text,
  26. test(# primary key (a, b)
  27. test(# );
  28. CREATE TABLE
  29. test=# create trigger tcndata_tcn_trigger
  30. test-# after insert or update or delete on tcndata
  31. test-# for each row execute function triggered_change_notification();
  32. CREATE TRIGGER
  33. test=# listen tcn;
  34. LISTEN
  35. test=# insert into tcndata values (1, date '2012-12-22', 'one'),
  36. test-# (1, date '2012-12-23', 'another'),
  37. test-# (2, date '2012-12-23', 'two');
  38. INSERT 0 3
  39. Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
  40. Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-23'" received from server process with PID 22770.
  41. Asynchronous notification "tcn" with payload ""tcndata",I,"a"='2',"b"='2012-12-23'" received from server process with PID 22770.
  42. test=# update tcndata set c = 'uno' where a = 1;
  43. UPDATE 2
  44. Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
  45. Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-23'" received from server process with PID 22770.
  46. test=# delete from tcndata where a = 1 and b = date '2012-12-22';
  47. DELETE 1
  48. Asynchronous notification "tcn" with payload ""tcndata",D,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
  49. </pre><p>
  50. </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>
上海开阖软件有限公司 沪ICP备12045867号-1