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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>34.5.Rules and Command Status</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="rules.html" title="Chapter34.The Rule System">
<link rel="prev" href="rules-privileges.html" title="34.4.Rules and Privileges">
<link rel="next" href="rules-triggers.html" title="34.6.Rules versus Triggers">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="rules-status"></a>34.5.Rules and Command Status</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 type="disc">
<li><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 may reduce the
number of rows it processes, and if so the reported status will
be affected.)
</p></li>
<li><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>
(This system was established in <span class="productname">PostgreSQL</span> 7.3.
In versions before that, the command status might show different
results when rules exist.)</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></body>
</html>
|