summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/html/rules-status.html
blob: 0503ca7081ff4af1afa16c4156417a3d91756303 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?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>41.6. Rules and Command Status</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="rules-privileges.html" title="41.5. Rules and Privileges" /><link rel="next" href="rules-triggers.html" title="41.7. Rules Versus Triggers" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">41.6. Rules and Command Status</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="rules-privileges.html" title="41.5. Rules and Privileges">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="rules.html" title="Chapter 41. The Rule System">Up</a></td><th width="60%" align="center">Chapter 41. The Rule System</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="rules-triggers.html" title="41.7. Rules Versus Triggers">Next</a></td></tr></table><hr /></div><div class="sect1" id="RULES-STATUS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">41.6. Rules and Command Status <a href="#RULES-STATUS" class="id_link">#</a></h2></div></div></div><p>
    The <span class="productname">PostgreSQL</span> server returns a command
    status string, such as <code class="literal">INSERT 149592 1</code>, for each
    command it receives.  This is simple enough when there are no rules
    involved, but what happens when the query is rewritten by rules?
</p><p>
    Rules affect the command status as follows:

    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       If there is no unconditional <code class="literal">INSTEAD</code> rule for the query, then
       the originally given query will be executed, and its command
       status will be returned as usual.  (But note that if there were
       any conditional <code class="literal">INSTEAD</code> rules, the negation of their qualifications
       will have been added to the original query.  This might reduce the
       number of rows it processes, and if so the reported status will
       be affected.)
      </p></li><li class="listitem"><p>
       If there is any unconditional <code class="literal">INSTEAD</code> rule for the query, then
       the original query will not be executed at all.  In this case,
       the server will return the command status for the last query
       that was inserted by an <code class="literal">INSTEAD</code> rule (conditional or
       unconditional) and is of the same command type
       (<code class="command">INSERT</code>, <code class="command">UPDATE</code>, or
       <code class="command">DELETE</code>) as the original query.  If no query
       meeting those requirements is added by any rule, then the
       returned command status shows the original query type and
       zeroes for the row-count and OID fields.
      </p></li></ul></div><p>
</p><p>
    The programmer can ensure that any desired <code class="literal">INSTEAD</code> rule is the one
    that sets the command status in the second case, by giving it the
    alphabetically last rule name among the active rules, so that it
    gets applied last.
</p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="rules-privileges.html" title="41.5. Rules and Privileges">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="rules.html" title="Chapter 41. The Rule System">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="rules-triggers.html" title="41.7. Rules Versus Triggers">Next</a></td></tr><tr><td width="40%" align="left" valign="top">41.5. Rules and Privileges </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"> 41.7. Rules Versus Triggers</td></tr></table></div></body></html>