Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
sql-set-constraints.html71 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>SET CONSTRAINTS</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-set.html" title="SET" /><link rel="next" href="sql-set-role.html" title="SET ROLE" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">SET CONSTRAINTS</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-set.html" title="SET">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-set-role.html" title="SET ROLE">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-SET-CONSTRAINTS"><div class="titlepage"></div><a id="id-1.9.3.175.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">SET CONSTRAINTS</span></h2><p>SET CONSTRAINTS — set constraint check timing for the current transaction</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">3SET CONSTRAINTS { ALL | <em class="replaceable"><code>name</code></em> [, ...] } { DEFERRED | IMMEDIATE }4</pre></div><div class="refsect1" id="id-1.9.3.175.5"><h2>Description</h2><p>5   <code class="command">SET CONSTRAINTS</code> sets the behavior of constraint6   checking within the current transaction. <code class="literal">IMMEDIATE</code>7   constraints are checked at the end of each8   statement. <code class="literal">DEFERRED</code> constraints are not checked until9   transaction commit.  Each constraint has its own10   <code class="literal">IMMEDIATE</code> or <code class="literal">DEFERRED</code> mode.11  </p><p>12   Upon creation, a constraint is given one of three13   characteristics: <code class="literal">DEFERRABLE INITIALLY DEFERRED</code>,14   <code class="literal">DEFERRABLE INITIALLY IMMEDIATE</code>, or15   <code class="literal">NOT DEFERRABLE</code>. The third16   class is always <code class="literal">IMMEDIATE</code> and is not affected by the17   <code class="command">SET CONSTRAINTS</code> command.  The first two classes start18   every transaction in the indicated mode, but their behavior can be changed19   within a transaction by <code class="command">SET CONSTRAINTS</code>.20  </p><p>21   <code class="command">SET CONSTRAINTS</code> with a list of constraint names changes22   the mode of just those constraints (which must all be deferrable).  Each23   constraint name can be schema-qualified.  The24   current schema search path is used to find the first matching name if25   no schema name is specified.  <code class="command">SET CONSTRAINTS ALL</code>26   changes the mode of all deferrable constraints.27  </p><p>28   When <code class="command">SET CONSTRAINTS</code> changes the mode of a constraint29   from <code class="literal">DEFERRED</code>30   to <code class="literal">IMMEDIATE</code>, the new mode takes effect31   retroactively: any outstanding data modifications that would have32   been checked at the end of the transaction are instead checked during the33   execution of the <code class="command">SET CONSTRAINTS</code> command.34   If any such constraint is violated, the <code class="command">SET CONSTRAINTS</code>35   fails (and does not change the constraint mode).  Thus, <code class="command">SET36   CONSTRAINTS</code> can be used to force checking of constraints to37   occur at a specific point in a transaction.38  </p><p>39   Currently, only <code class="literal">UNIQUE</code>, <code class="literal">PRIMARY KEY</code>,40   <code class="literal">REFERENCES</code> (foreign key), and <code class="literal">EXCLUDE</code>41   constraints are affected by this setting.42   <code class="literal">NOT NULL</code> and <code class="literal">CHECK</code> constraints are43   always checked immediately when a row is inserted or modified44   (<span class="emphasis"><em>not</em></span> at the end of the statement).45   Uniqueness and exclusion constraints that have not been declared46   <code class="literal">DEFERRABLE</code> are also checked immediately.47  </p><p>48   The firing of triggers that are declared as <span class="quote">“<span class="quote">constraint triggers</span>”</span>49   is also controlled by this setting — they fire at the same time50   that the associated constraint should be checked.51  </p></div><div class="refsect1" id="id-1.9.3.175.6"><h2>Notes</h2><p>52   Because <span class="productname">PostgreSQL</span> does not require constraint53   names to be unique within a schema (but only per-table), it is possible54   that there is more than one match for a specified constraint name.55   In this case <code class="command">SET CONSTRAINTS</code> will act on all matches.56   For a non-schema-qualified name, once a match or matches have been found in57   some schema in the search path, schemas appearing later in the path are not58   searched.59  </p><p>60   This command only alters the behavior of constraints within the61   current transaction.  Issuing this outside of a transaction block62   emits a warning and otherwise has no effect.63  </p></div><div class="refsect1" id="id-1.9.3.175.7"><h2>Compatibility</h2><p>64   This command complies with the behavior defined in the SQL65   standard, except for the limitation that, in66   <span class="productname">PostgreSQL</span>, it does not apply to67   <code class="literal">NOT NULL</code> and <code class="literal">CHECK</code> constraints.68   Also, <span class="productname">PostgreSQL</span> checks non-deferrable69   uniqueness constraints immediately, not at end of statement as the70   standard would suggest.71  </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-set.html" title="SET">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-set-role.html" title="SET ROLE">Next</a></td></tr><tr><td width="40%" align="left" valign="top">SET </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"> SET ROLE</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai