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.

40 lines
5.1KB

  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>45.6. 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="plpython-do.html" title="45.5. Anonymous Code Blocks" /><link rel="next" href="plpython-database.html" title="45.7. Database Access" /></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">45.6. Trigger Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="plpython-do.html" title="45.5. Anonymous Code Blocks">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="plpython.html" title="Chapter 45. PL/Python - Python Procedural Language">Up</a></td><th width="60%" align="center">Chapter 45. PL/Python - Python Procedural Language</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="plpython-database.html" title="45.7. Database Access">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="PLPYTHON-TRIGGER"><div class="titlepage"><div><div><h2 class="title" style="clear: both">45.6. Trigger Functions</h2></div></div></div><a id="id-1.8.11.14.2" class="indexterm"></a><p>
  3. When a function is used as a trigger, the dictionary
  4. <code class="literal">TD</code> contains trigger-related values:
  5. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">TD["event"]</code></span></dt><dd><p>
  6. contains the event as a string:
  7. <code class="literal">INSERT</code>, <code class="literal">UPDATE</code>,
  8. <code class="literal">DELETE</code>, or <code class="literal">TRUNCATE</code>.
  9. </p></dd><dt><span class="term"><code class="literal">TD["when"]</code></span></dt><dd><p>
  10. contains one of <code class="literal">BEFORE</code>, <code class="literal">AFTER</code>, or
  11. <code class="literal">INSTEAD OF</code>.
  12. </p></dd><dt><span class="term"><code class="literal">TD["level"]</code></span></dt><dd><p>
  13. contains <code class="literal">ROW</code> or <code class="literal">STATEMENT</code>.
  14. </p></dd><dt><span class="term"><code class="literal">TD["new"]</code><br /></span><span class="term"><code class="literal">TD["old"]</code></span></dt><dd><p>
  15. For a row-level trigger, one or both of these fields contain
  16. the respective trigger rows, depending on the trigger event.
  17. </p></dd><dt><span class="term"><code class="literal">TD["name"]</code></span></dt><dd><p>
  18. contains the trigger name.
  19. </p></dd><dt><span class="term"><code class="literal">TD["table_name"]</code></span></dt><dd><p>
  20. contains the name of the table on which the trigger occurred.
  21. </p></dd><dt><span class="term"><code class="literal">TD["table_schema"]</code></span></dt><dd><p>
  22. contains the schema of the table on which the trigger occurred.
  23. </p></dd><dt><span class="term"><code class="literal">TD["relid"]</code></span></dt><dd><p>
  24. contains the OID of the table on which the trigger occurred.
  25. </p></dd><dt><span class="term"><code class="literal">TD["args"]</code></span></dt><dd><p>
  26. If the <code class="command">CREATE TRIGGER</code> command
  27. included arguments, they are available in <code class="literal">TD["args"][0]</code> to
  28. <code class="literal">TD["args"][<em class="replaceable"><code>n</code></em>-1]</code>.
  29. </p></dd></dl></div><p>
  30. </p><p>
  31. If <code class="literal">TD["when"]</code> is <code class="literal">BEFORE</code> or
  32. <code class="literal">INSTEAD OF</code> and
  33. <code class="literal">TD["level"]</code> is <code class="literal">ROW</code>, you can
  34. return <code class="literal">None</code> or <code class="literal">"OK"</code> from the
  35. Python function to indicate the row is unmodified,
  36. <code class="literal">"SKIP"</code> to abort the event, or if <code class="literal">TD["event"]</code>
  37. is <code class="command">INSERT</code> or <code class="command">UPDATE</code> you can return
  38. <code class="literal">"MODIFY"</code> to indicate you've modified the new row.
  39. Otherwise the return value is ignored.
  40. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="plpython-do.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="plpython.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="plpython-database.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">45.5. Anonymous Code Blocks </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 45.7. Database Access</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1