|
- <?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>9.27. 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-admin.html" title="9.26. System Administration Functions" /><link rel="next" href="functions-event-triggers.html" title="9.28. Event Trigger 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.27. Trigger Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-admin.html" title="9.26. System Administration 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-event-triggers.html" title="9.28. Event Trigger Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FUNCTIONS-TRIGGER"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.27. Trigger Functions</h2></div></div></div><a id="id-1.5.8.32.2" class="indexterm"></a><p>
- Currently <span class="productname">PostgreSQL</span> provides one built in trigger
- function, <code class="function">suppress_redundant_updates_trigger</code>,
- which will prevent any update
- that does not actually change the data in the row from taking place, in
- contrast to the normal behavior which always performs the update
- regardless of whether or not the data has changed. (This normal behavior
- makes updates run faster, since no checking is required, and is also
- useful in certain cases.)
- </p><p>
- Ideally, you should normally avoid running updates that don't actually
- change the data in the record. Redundant updates can cost considerable
- unnecessary time, especially if there are lots of indexes to alter,
- and space in dead rows that will eventually have to be vacuumed.
- However, detecting such situations in client code is not
- always easy, or even possible, and writing expressions to detect
- them can be error-prone. An alternative is to use
- <code class="function">suppress_redundant_updates_trigger</code>, which will skip
- updates that don't change the data. You should use this with care,
- however. The trigger takes a small but non-trivial time for each record,
- so if most of the records affected by an update are actually changed,
- use of this trigger will actually make the update run slower.
- </p><p>
- The <code class="function">suppress_redundant_updates_trigger</code> function can be
- added to a table like this:
- </p><pre class="programlisting">
- CREATE TRIGGER z_min_update
- BEFORE UPDATE ON tablename
- FOR EACH ROW EXECUTE FUNCTION suppress_redundant_updates_trigger();
- </pre><p>
- In most cases, you would want to fire this trigger last for each row.
- Bearing in mind that triggers fire in name order, you would then
- choose a trigger name that comes after the name of any other trigger
- you might have on the table.
- </p><p>
- For more information about creating triggers, see
- <a class="xref" href="sql-createtrigger.html" title="CREATE TRIGGER"><span class="refentrytitle">CREATE TRIGGER</span></a>.
- </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-admin.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-event-triggers.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.26. System Administration Functions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 9.28. Event Trigger Functions</td></tr></table></div></body></html>
|