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>39.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="39.5. Rules and Privileges" /><link rel="next" href="rules-triggers.html" title="39.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">39.6. Rules and Command Status</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="rules-privileges.html" title="39.5. Rules and Privileges">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="rules.html" title="Chapter 39. The Rule System">Up</a></td><th width="60%" align="center">Chapter 39. The Rule System</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="rules-triggers.html" title="39.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">39.6. Rules and Command Status <a href="#RULES-STATUS" class="id_link">#</a></h2></div></div></div><p>
3 The <span class="productname">PostgreSQL</span> server returns a command
4 status string, such as <code class="literal">INSERT 149592 1</code>, for each
5 command it receives. This is simple enough when there are no rules
6 involved, but what happens when the query is rewritten by rules?
8 Rules affect the command status as follows:
10 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
11 If there is no unconditional <code class="literal">INSTEAD</code> rule for the query, then
12 the originally given query will be executed, and its command
13 status will be returned as usual. (But note that if there were
14 any conditional <code class="literal">INSTEAD</code> rules, the negation of their qualifications
15 will have been added to the original query. This might reduce the
16 number of rows it processes, and if so the reported status will
18 </p></li><li class="listitem"><p>
19 If there is any unconditional <code class="literal">INSTEAD</code> rule for the query, then
20 the original query will not be executed at all. In this case,
21 the server will return the command status for the last query
22 that was inserted by an <code class="literal">INSTEAD</code> rule (conditional or
23 unconditional) and is of the same command type
24 (<code class="command">INSERT</code>, <code class="command">UPDATE</code>, or
25 <code class="command">DELETE</code>) as the original query. If no query
26 meeting those requirements is added by any rule, then the
27 returned command status shows the original query type and
28 zeroes for the row-count and OID fields.
29 </p></li></ul></div><p>
31 The programmer can ensure that any desired <code class="literal">INSTEAD</code> rule is the one
32 that sets the command status in the second case, by giving it the
33 alphabetically last rule name among the active rules, so that it
35 </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="39.5. Rules and Privileges">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="rules.html" title="Chapter 39. The Rule System">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="rules-triggers.html" title="39.7. Rules Versus Triggers">Next</a></td></tr><tr><td width="40%" align="left" valign="top">39.5. Rules and Privileges </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 39.7. Rules Versus Triggers</td></tr></table></div></body></html>