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.

120 lines
12KB

  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>9.28. Event Trigger Functions</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="functions-trigger.html" title="9.27. Trigger Functions" /><link rel="next" href="functions-statistics.html" title="9.29. Statistics Information Functions" /></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">9.28. Event Trigger Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-trigger.html" title="9.27. Trigger Functions">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</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="functions-statistics.html" title="9.29. Statistics Information Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FUNCTIONS-EVENT-TRIGGERS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.28. Event Trigger Functions</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="functions-event-triggers.html#PG-EVENT-TRIGGER-DDL-COMMAND-END-FUNCTIONS">9.28.1. Capturing Changes at Command End</a></span></dt><dt><span class="sect2"><a href="functions-event-triggers.html#PG-EVENT-TRIGGER-SQL-DROP-FUNCTIONS">9.28.2. Processing Objects Dropped by a DDL Command</a></span></dt><dt><span class="sect2"><a href="functions-event-triggers.html#PG-EVENT-TRIGGER-TABLE-REWRITE-FUNCTIONS">9.28.3. Handling a Table Rewrite Event</a></span></dt></dl></div><p>
  3. <span class="productname">PostgreSQL</span> provides these helper functions
  4. to retrieve information from event triggers.
  5. </p><p>
  6. For more information about event triggers,
  7. see <a class="xref" href="event-triggers.html" title="Chapter 39. Event Triggers">Chapter 39</a>.
  8. </p><div class="sect2" id="PG-EVENT-TRIGGER-DDL-COMMAND-END-FUNCTIONS"><div class="titlepage"><div><div><h3 class="title">9.28.1. Capturing Changes at Command End</h3></div></div></div><a id="id-1.5.8.33.4.2" class="indexterm"></a><p>
  9. <code class="function">pg_event_trigger_ddl_commands</code> returns a list of
  10. <acronym class="acronym">DDL</acronym> commands executed by each user action,
  11. when invoked in a function attached to a
  12. <code class="literal">ddl_command_end</code> event trigger. If called in any other
  13. context, an error is raised.
  14. <code class="function">pg_event_trigger_ddl_commands</code> returns one row for each
  15. base command executed; some commands that are a single SQL sentence
  16. may return more than one row. This function returns the following
  17. columns:
  18. </p><div class="informaltable"><table class="informaltable" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="literal">classid</code></td><td><code class="type">oid</code></td><td>OID of catalog the object belongs in</td></tr><tr><td><code class="literal">objid</code></td><td><code class="type">oid</code></td><td>OID of the object itself</td></tr><tr><td><code class="literal">objsubid</code></td><td><code class="type">integer</code></td><td>Sub-object ID (e.g. attribute number for a column)</td></tr><tr><td><code class="literal">command_tag</code></td><td><code class="type">text</code></td><td>Command tag</td></tr><tr><td><code class="literal">object_type</code></td><td><code class="type">text</code></td><td>Type of the object</td></tr><tr><td><code class="literal">schema_name</code></td><td><code class="type">text</code></td><td>
  19. Name of the schema the object belongs in, if any; otherwise <code class="literal">NULL</code>.
  20. No quoting is applied.
  21. </td></tr><tr><td><code class="literal">object_identity</code></td><td><code class="type">text</code></td><td>
  22. Text rendering of the object identity, schema-qualified. Each
  23. identifier included in the identity is quoted if necessary.
  24. </td></tr><tr><td><code class="literal">in_extension</code></td><td><code class="type">bool</code></td><td>True if the command is part of an extension script</td></tr><tr><td><code class="literal">command</code></td><td><code class="type">pg_ddl_command</code></td><td>
  25. A complete representation of the command, in internal format.
  26. This cannot be output directly, but it can be passed to other
  27. functions to obtain different pieces of information about the
  28. command.
  29. </td></tr></tbody></table></div><p>
  30. </p></div><div class="sect2" id="PG-EVENT-TRIGGER-SQL-DROP-FUNCTIONS"><div class="titlepage"><div><div><h3 class="title">9.28.2. Processing Objects Dropped by a DDL Command</h3></div></div></div><a id="id-1.5.8.33.5.2" class="indexterm"></a><p>
  31. <code class="function">pg_event_trigger_dropped_objects</code> returns a list of all objects
  32. dropped by the command in whose <code class="literal">sql_drop</code> event it is called.
  33. If called in any other context,
  34. <code class="function">pg_event_trigger_dropped_objects</code> raises an error.
  35. <code class="function">pg_event_trigger_dropped_objects</code> returns the following columns:
  36. </p><div class="informaltable"><table class="informaltable" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="literal">classid</code></td><td><code class="type">oid</code></td><td>OID of catalog the object belonged in</td></tr><tr><td><code class="literal">objid</code></td><td><code class="type">oid</code></td><td>OID of the object itself</td></tr><tr><td><code class="literal">objsubid</code></td><td><code class="type">integer</code></td><td>Sub-object ID (e.g. attribute number for a column)</td></tr><tr><td><code class="literal">original</code></td><td><code class="type">bool</code></td><td>True if this was one of the root object(s) of the deletion</td></tr><tr><td><code class="literal">normal</code></td><td><code class="type">bool</code></td><td>
  37. True if there was a normal dependency relationship
  38. in the dependency graph leading to this object
  39. </td></tr><tr><td><code class="literal">is_temporary</code></td><td><code class="type">bool</code></td><td>
  40. True if this was a temporary object
  41. </td></tr><tr><td><code class="literal">object_type</code></td><td><code class="type">text</code></td><td>Type of the object</td></tr><tr><td><code class="literal">schema_name</code></td><td><code class="type">text</code></td><td>
  42. Name of the schema the object belonged in, if any; otherwise <code class="literal">NULL</code>.
  43. No quoting is applied.
  44. </td></tr><tr><td><code class="literal">object_name</code></td><td><code class="type">text</code></td><td>
  45. Name of the object, if the combination of schema and name can be
  46. used as a unique identifier for the object; otherwise <code class="literal">NULL</code>.
  47. No quoting is applied, and name is never schema-qualified.
  48. </td></tr><tr><td><code class="literal">object_identity</code></td><td><code class="type">text</code></td><td>
  49. Text rendering of the object identity, schema-qualified. Each
  50. identifier included in the identity is quoted if necessary.
  51. </td></tr><tr><td><code class="literal">address_names</code></td><td><code class="type">text[]</code></td><td>
  52. An array that, together with <code class="literal">object_type</code> and
  53. <code class="literal">address_args</code>, can be used by
  54. the <code class="function">pg_get_object_address()</code> function to
  55. recreate the object address in a remote server containing an
  56. identically named object of the same kind
  57. </td></tr><tr><td><code class="literal">address_args</code></td><td><code class="type">text[]</code></td><td>
  58. Complement for <code class="literal">address_names</code>
  59. </td></tr></tbody></table></div><p>
  60. </p><p>
  61. The <code class="function">pg_event_trigger_dropped_objects</code> function can be used
  62. in an event trigger like this:
  63. </p><pre class="programlisting">
  64. CREATE FUNCTION test_event_trigger_for_drops()
  65. RETURNS event_trigger LANGUAGE plpgsql AS $$
  66. DECLARE
  67. obj record;
  68. BEGIN
  69. FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects()
  70. LOOP
  71. RAISE NOTICE '% dropped object: % %.% %',
  72. tg_tag,
  73. obj.object_type,
  74. obj.schema_name,
  75. obj.object_name,
  76. obj.object_identity;
  77. END LOOP;
  78. END
  79. $$;
  80. CREATE EVENT TRIGGER test_event_trigger_for_drops
  81. ON sql_drop
  82. EXECUTE FUNCTION test_event_trigger_for_drops();
  83. </pre><p>
  84. </p></div><div class="sect2" id="PG-EVENT-TRIGGER-TABLE-REWRITE-FUNCTIONS"><div class="titlepage"><div><div><h3 class="title">9.28.3. Handling a Table Rewrite Event</h3></div></div></div><p>
  85. The functions shown in
  86. <a class="xref" href="functions-event-triggers.html#FUNCTIONS-EVENT-TRIGGER-TABLE-REWRITE" title="Table 9.96. Table Rewrite Information">Table 9.96</a>
  87. provide information about a table for which a
  88. <code class="literal">table_rewrite</code> event has just been called.
  89. If called in any other context, an error is raised.
  90. </p><div class="table" id="FUNCTIONS-EVENT-TRIGGER-TABLE-REWRITE"><p class="title"><strong>Table 9.96. Table Rewrite Information</strong></p><div class="table-contents"><table class="table" summary="Table Rewrite Information" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>
  91. <a id="id-1.5.8.33.6.3.2.2.1.1.1" class="indexterm"></a>
  92. <code class="literal"><code class="function">pg_event_trigger_table_rewrite_oid()</code></code>
  93. </td><td><code class="type">Oid</code></td><td>The OID of the table about to be rewritten.</td></tr><tr><td>
  94. <a id="id-1.5.8.33.6.3.2.2.2.1.1" class="indexterm"></a>
  95. <code class="literal"><code class="function">pg_event_trigger_table_rewrite_reason()</code></code>
  96. </td><td><code class="type">int</code></td><td>
  97. The reason code(s) explaining the reason for rewriting. The exact
  98. meaning of the codes is release dependent.
  99. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  100. The <code class="function">pg_event_trigger_table_rewrite_oid</code> function can be used
  101. in an event trigger like this:
  102. </p><pre class="programlisting">
  103. CREATE FUNCTION test_event_trigger_table_rewrite_oid()
  104. RETURNS event_trigger
  105. LANGUAGE plpgsql AS
  106. $$
  107. BEGIN
  108. RAISE NOTICE 'rewriting table % for reason %',
  109. pg_event_trigger_table_rewrite_oid()::regclass,
  110. pg_event_trigger_table_rewrite_reason();
  111. END;
  112. $$;
  113. CREATE EVENT TRIGGER test_table_rewrite_oid
  114. ON table_rewrite
  115. EXECUTE FUNCTION test_event_trigger_table_rewrite_oid();
  116. </pre><p>
  117. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-trigger.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-statistics.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.27. Trigger Functions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 9.29. Statistics Information Functions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1