Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
sql-createeventtrigger.html65 linesDownload Raw Back to html
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>CREATE EVENT TRIGGER</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="sql-createdomain.html" title="CREATE DOMAIN" /><link rel="next" href="sql-createextension.html" title="CREATE EXTENSION" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">CREATE EVENT TRIGGER</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createdomain.html" title="CREATE DOMAIN">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-createextension.html" title="CREATE EXTENSION">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-CREATEEVENTTRIGGER"><div class="titlepage"></div><a id="id-1.9.3.63.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE EVENT TRIGGER</span></h2><p>CREATE EVENT TRIGGER — define a new event trigger</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">3CREATE EVENT TRIGGER <em class="replaceable"><code>name</code></em>4    ON <em class="replaceable"><code>event</code></em>5    [ WHEN <em class="replaceable"><code>filter_variable</code></em> IN (<em class="replaceable"><code>filter_value</code></em> [, ... ]) [ AND ... ] ]6    EXECUTE { FUNCTION | PROCEDURE } <em class="replaceable"><code>function_name</code></em>()7</pre></div><div class="refsect1" id="id-1.9.3.63.5"><h2>Description</h2><p>8   <code class="command">CREATE EVENT TRIGGER</code> creates a new event trigger.9   Whenever the designated event occurs and the <code class="literal">WHEN</code> condition10   associated with the trigger, if any, is satisfied, the trigger function11   will be executed.  For a general introduction to event triggers, see12   <a class="xref" href="event-triggers.html" title="Chapter 40. Event Triggers">Chapter 40</a>.  The user who creates an event trigger13   becomes its owner.14  </p></div><div class="refsect1" id="id-1.9.3.63.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>15      The name to give the new trigger.  This name must be unique within16      the database.17     </p></dd><dt><span class="term"><em class="replaceable"><code>event</code></em></span></dt><dd><p>18      The name of the event that triggers a call to the given function.19      See <a class="xref" href="event-trigger-definition.html" title="40.1. Overview of Event Trigger Behavior">Section 40.1</a> for more information20      on event names.21     </p></dd><dt><span class="term"><em class="replaceable"><code>filter_variable</code></em></span></dt><dd><p>22      The name of a variable used to filter events.  This makes it possible23      to restrict the firing of the trigger to a subset of the cases in which24      it is supported.  Currently the only supported25      <em class="replaceable"><code>filter_variable</code></em>26      is <code class="literal">TAG</code>.27     </p></dd><dt><span class="term"><em class="replaceable"><code>filter_value</code></em></span></dt><dd><p>28      A list of values for the29      associated <em class="replaceable"><code>filter_variable</code></em>30      for which the trigger should fire.  For <code class="literal">TAG</code>, this means a31      list of command tags (e.g., <code class="literal">'DROP FUNCTION'</code>).32     </p></dd><dt><span class="term"><em class="replaceable"><code>function_name</code></em></span></dt><dd><p>33      A user-supplied function that is declared as taking no argument and34      returning type <code class="literal">event_trigger</code>.35     </p><p>36      In the syntax of <code class="literal">CREATE EVENT TRIGGER</code>, the keywords37      <code class="literal">FUNCTION</code> and <code class="literal">PROCEDURE</code> are38      equivalent, but the referenced function must in any case be a function,39      not a procedure.  The use of the keyword <code class="literal">PROCEDURE</code>40      here is historical and deprecated.41     </p></dd></dl></div></div><div class="refsect1" id="SQL-CREATEEVENTTRIGGER-NOTES"><h2>Notes</h2><p>42   Only superusers can create event triggers.43  </p><p>44   Event triggers are disabled in single-user mode (see <a class="xref" href="app-postgres.html" title="postgres"><span class="refentrytitle"><span class="application">postgres</span></span></a>).  If an erroneous event trigger disables the45   database so much that you can't even drop the trigger, restart in46   single-user mode and you'll be able to do that.47  </p></div><div class="refsect1" id="SQL-CREATEEVENTTRIGGER-EXAMPLES"><h2>Examples</h2><p>48   Forbid the execution of any <a class="link" href="ddl.html" title="Chapter 5. Data Definition">DDL</a> command:49 50</p><pre class="programlisting">51CREATE OR REPLACE FUNCTION abort_any_command()52  RETURNS event_trigger53 LANGUAGE plpgsql54  AS $$55BEGIN56  RAISE EXCEPTION 'command % is disabled', tg_tag;57END;58$$;59 60CREATE EVENT TRIGGER abort_ddl ON ddl_command_start61   EXECUTE FUNCTION abort_any_command();62</pre></div><div class="refsect1" id="SQL-CREATEEVENTTRIGGER-COMPATIBILITY"><h2>Compatibility</h2><p>63   There is no <code class="command">CREATE EVENT TRIGGER</code> statement in the64   SQL standard.65  </p></div><div class="refsect1" id="id-1.9.3.63.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-altereventtrigger.html" title="ALTER EVENT TRIGGER"><span class="refentrytitle">ALTER EVENT TRIGGER</span></a>, <a class="xref" href="sql-dropeventtrigger.html" title="DROP EVENT TRIGGER"><span class="refentrytitle">DROP EVENT TRIGGER</span></a>, <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-createdomain.html" title="CREATE DOMAIN">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-createextension.html" title="CREATE EXTENSION">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE DOMAIN </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE EXTENSION</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai