Commit d08889aa authored by Bruce Momjian's avatar Bruce Momjian

Add tools/find_gt_lt to find < and > in SGML source.

Lowercase some uppercase tags so tools is more reliable at finding
problems.
parent bdbfd343
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/client-auth.sgml,v 1.70 2004/12/27 19:19:23 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/client-auth.sgml,v 1.71 2005/01/23 00:30:18 momjian Exp $
--> -->
<chapter id="client-authentication"> <chapter id="client-authentication">
...@@ -892,9 +892,9 @@ omicron bryanh guest1 ...@@ -892,9 +892,9 @@ omicron bryanh guest1
</para> </para>
<para> <para>
<ProgramListing> <programlisting>
FATAL: no pg_hba.conf entry for host "123.123.123.123", user "andym", database "testdb" FATAL: no pg_hba.conf entry for host "123.123.123.123", user "andym", database "testdb"
</ProgramListing> </programlisting>
This is what you are most likely to get if you succeed in contacting This is what you are most likely to get if you succeed in contacting
the server, but it does not want to talk to you. As the message the server, but it does not want to talk to you. As the message
suggests, the server refused the connection request because it found suggests, the server refused the connection request because it found
...@@ -903,9 +903,9 @@ FATAL: no pg_hba.conf entry for host "123.123.123.123", user "andym", database ...@@ -903,9 +903,9 @@ FATAL: no pg_hba.conf entry for host "123.123.123.123", user "andym", database
</para> </para>
<para> <para>
<ProgramListing> <programlisting>
FATAL: Password authentication failed for user "andym" FATAL: Password authentication failed for user "andym"
</ProgramListing> </programlisting>
Messages like this indicate that you contacted the server, and it is Messages like this indicate that you contacted the server, and it is
willing to talk to you, but not until you pass the authorization willing to talk to you, but not until you pass the authorization
method specified in the <filename>pg_hba.conf</filename> file. Check method specified in the <filename>pg_hba.conf</filename> file. Check
...@@ -915,16 +915,16 @@ FATAL: Password authentication failed for user "andym" ...@@ -915,16 +915,16 @@ FATAL: Password authentication failed for user "andym"
</para> </para>
<para> <para>
<ProgramListing> <programlisting>
FATAL: user "andym" does not exist FATAL: user "andym" does not exist
</ProgramListing> </programlisting>
The indicated user name was not found. The indicated user name was not found.
</para> </para>
<para> <para>
<ProgramListing> <programlisting>
FATAL: database "testdb" does not exist FATAL: database "testdb" does not exist
</ProgramListing> </programlisting>
The database you are trying to connect to does not exist. Note that The database you are trying to connect to does not exist. Note that
if you do not specify a database name, it defaults to the database if you do not specify a database name, it defaults to the database
user name, which may or may not be the right thing. user name, which may or may not be the right thing.
......
<Appendix Label="B" Id="contacts"> <appendix label="B" id="contacts">
<Title>Contacts</Title> <title>Contacts</title>
<!-- <!--
<Para> <para>
Support for <productname>PostgreSQL</productname> comes primarily from Support for <productname>PostgreSQL</productname> comes primarily from
this printed documentation, the web-based mailing list archives, this printed documentation, the web-based mailing list archives,
and the mailing lists themselves. and the mailing lists themselves.
</Para> </para>
<Sect1 id="mailing-list"> <sect1 id="mailing-list">
<Title>Mailing Lists</Title> <title>Mailing Lists</title>
<Para> <para>
Refer to the introduction in this manual or to the Refer to the introduction in this manual or to the
<ulink url="http://www.postgresql.org"><productname>PostgreSQL</productname> web page</ulink> <ulink url="http://www.postgresql.org"><productname>PostgreSQL</productname> web page</ulink>
for subscription information to the no-cost mailing lists. for subscription information to the no-cost mailing lists.
</Para> </para>
<Sect1 id="people"> <sect1 id="people">
<Title>People</Title> <title>People</title>
--> -->
<Para> <para>
<ItemizedList Mark="bullet" Spacing="compact"> <itemizedlist mark="bullet" spacing="compact">
<ListItem> <listitem>
<Para> <para>
<ULink url="lockhart@fourpalms.org">Thomas Lockhart</ULink> <ulink url="lockhart@fourpalms.org">Thomas Lockhart</ulink>
works on SQL standards compliance and documentation. works on SQL standards compliance and documentation.
</Para> </para>
</ListItem> </listitem>
</ItemizedList> </itemizedlist>
</Para> </para>
</Appendix> </appendix>
<!-- $PostgreSQL: pgsql/doc/src/sgml/installation.sgml,v 1.228 2005/01/17 02:29:23 petere Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/installation.sgml,v 1.229 2005/01/23 00:30:18 momjian Exp $ -->
<chapter id="installation"> <chapter id="installation">
<title><![%standalone-include[<productname>PostgreSQL</>]]> <title><![%standalone-include[<productname>PostgreSQL</>]]>
...@@ -249,7 +249,7 @@ su - postgres ...@@ -249,7 +249,7 @@ su - postgres
class="osname">Linux</>, <systemitem class="osname">NetBSD</>, class="osname">Linux</>, <systemitem class="osname">NetBSD</>,
<systemitem class="osname">Solaris</>), for other systems you <systemitem class="osname">Solaris</>), for other systems you
can download an add-on package from here: <ulink can download an add-on package from here: <ulink
url="http://developer.postgresql.org/~petere/bsd-gettext/" ></ulink>. url="http://developer.postgresql.org/~petere/bsd-gettext/"></ulink>.
If you are using the <application>Gettext</> implementation in If you are using the <application>Gettext</> implementation in
the <acronym>GNU</acronym> C library then you will additionally the <acronym>GNU</acronym> C library then you will additionally
need the <productname>GNU Gettext</productname> package for some need the <productname>GNU Gettext</productname> package for some
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/protocol.sgml,v 1.57 2004/12/20 18:15:05 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/protocol.sgml,v 1.58 2005/01/23 00:30:18 momjian Exp $ -->
<chapter id="protocol"> <chapter id="protocol">
<title>Frontend/Backend Protocol</title> <title>Frontend/Backend Protocol</title>
...@@ -210,7 +210,7 @@ ...@@ -210,7 +210,7 @@
</para> </para>
<sect2> <sect2>
<title>Start-Up</Title> <title>Start-Up</title>
<para> <para>
To begin a session, a frontend opens a connection to the server and sends To begin a session, a frontend opens a connection to the server and sends
...@@ -265,7 +265,7 @@ ...@@ -265,7 +265,7 @@
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>AuthenticationKerberosV4</Term> <term>AuthenticationKerberosV4</term>
<listitem> <listitem>
<para> <para>
The frontend must now take part in a Kerberos V4 The frontend must now take part in a Kerberos V4
...@@ -278,60 +278,60 @@ ...@@ -278,60 +278,60 @@
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<Term>AuthenticationKerberosV5</Term> <term>AuthenticationKerberosV5</term>
<ListItem> <listitem>
<Para> <para>
The frontend must now take part in a Kerberos V5 The frontend must now take part in a Kerberos V5
authentication dialog (not described here, part of the authentication dialog (not described here, part of the
Kerberos specification) with the server. If this is Kerberos specification) with the server. If this is
successful, the server responds with an AuthenticationOk, successful, the server responds with an AuthenticationOk,
otherwise it responds with an ErrorResponse. otherwise it responds with an ErrorResponse.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>AuthenticationCleartextPassword</Term> <term>AuthenticationCleartextPassword</term>
<ListItem> <listitem>
<Para> <para>
The frontend must now send a PasswordMessage containing the The frontend must now send a PasswordMessage containing the
password in clear-text form. If password in clear-text form. If
this is the correct password, the server responds with an this is the correct password, the server responds with an
AuthenticationOk, otherwise it responds with an ErrorResponse. AuthenticationOk, otherwise it responds with an ErrorResponse.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>AuthenticationCryptPassword</Term> <term>AuthenticationCryptPassword</term>
<ListItem> <listitem>
<Para> <para>
The frontend must now send a PasswordMessage containing the The frontend must now send a PasswordMessage containing the
password encrypted via crypt(3), using the 2-character salt password encrypted via crypt(3), using the 2-character salt
specified in the AuthenticationCryptPassword message. If specified in the AuthenticationCryptPassword message. If
this is the correct password, the server responds with an this is the correct password, the server responds with an
AuthenticationOk, otherwise it responds with an ErrorResponse. AuthenticationOk, otherwise it responds with an ErrorResponse.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>AuthenticationMD5Password</Term> <term>AuthenticationMD5Password</term>
<ListItem> <listitem>
<Para> <para>
The frontend must now send a PasswordMessage containing the The frontend must now send a PasswordMessage containing the
password encrypted via MD5, using the 4-character salt password encrypted via MD5, using the 4-character salt
specified in the AuthenticationMD5Password message. If specified in the AuthenticationMD5Password message. If
this is the correct password, the server responds with an this is the correct password, the server responds with an
AuthenticationOk, otherwise it responds with an ErrorResponse. AuthenticationOk, otherwise it responds with an ErrorResponse.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>AuthenticationSCMCredential</Term> <term>AuthenticationSCMCredential</term>
<ListItem> <listitem>
<Para> <para>
This response is only possible for local Unix-domain connections This response is only possible for local Unix-domain connections
on platforms that support SCM credential messages. The frontend on platforms that support SCM credential messages. The frontend
must issue an SCM credential message and then send a single data must issue an SCM credential message and then send a single data
...@@ -340,12 +340,12 @@ ...@@ -340,12 +340,12 @@
the credential message.) If the credential is acceptable, the credential message.) If the credential is acceptable,
the server responds with an the server responds with an
AuthenticationOk, otherwise it responds with an ErrorResponse. AuthenticationOk, otherwise it responds with an ErrorResponse.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
<para> <para>
If the frontend does not support the authentication method If the frontend does not support the authentication method
...@@ -372,23 +372,23 @@ ...@@ -372,23 +372,23 @@
<para> <para>
The possible messages from the backend in this phase are: The possible messages from the backend in this phase are:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term>BackendKeyData</Term> <term>BackendKeyData</term>
<ListItem> <listitem>
<Para> <para>
This message provides secret-key data that the frontend must This message provides secret-key data that the frontend must
save if it wants to be able to issue cancel requests later. save if it wants to be able to issue cancel requests later.
The frontend should not respond to this message, but should The frontend should not respond to this message, but should
continue listening for a ReadyForQuery message. continue listening for a ReadyForQuery message.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>ParameterStatus</Term> <term>ParameterStatus</term>
<ListItem> <listitem>
<Para> <para>
This message informs the frontend about the current (initial) This message informs the frontend about the current (initial)
setting of backend parameters, such as <xref setting of backend parameters, such as <xref
linkend="guc-client-encoding"> or <xref linkend="guc-datestyle">. linkend="guc-client-encoding"> or <xref linkend="guc-datestyle">.
...@@ -397,41 +397,41 @@ ...@@ -397,41 +397,41 @@
more details. The frontend should not respond to this more details. The frontend should not respond to this
message, but should continue listening for a ReadyForQuery message, but should continue listening for a ReadyForQuery
message. message.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>ReadyForQuery</Term> <term>ReadyForQuery</term>
<ListItem> <listitem>
<Para> <para>
Start-up is completed. The frontend may now issue commands. Start-up is completed. The frontend may now issue commands.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>ErrorResponse</Term> <term>ErrorResponse</term>
<ListItem> <listitem>
<Para> <para>
Start-up failed. The connection is closed after sending this Start-up failed. The connection is closed after sending this
message. message.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>NoticeResponse</Term> <term>NoticeResponse</term>
<ListItem> <listitem>
<Para> <para>
A warning message has been issued. The frontend should A warning message has been issued. The frontend should
display the message but continue listening for ReadyForQuery display the message but continue listening for ReadyForQuery
or ErrorResponse. or ErrorResponse.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
<para> <para>
The ReadyForQuery message is the same one that the backend will The ReadyForQuery message is the same one that the backend will
...@@ -442,10 +442,10 @@ ...@@ -442,10 +442,10 @@
</para> </para>
</sect2> </sect2>
<Sect2> <sect2>
<Title>Simple Query</Title> <title>Simple Query</title>
<Para> <para>
A simple query cycle is initiated by the frontend sending a Query message A simple query cycle is initiated by the frontend sending a Query message
to the backend. The message includes an SQL command (or commands) to the backend. The message includes an SQL command (or commands)
expressed as a text string. expressed as a text string.
...@@ -459,109 +459,109 @@ ...@@ -459,109 +459,109 @@
command fails and already-issued later commands succeed.) command fails and already-issued later commands succeed.)
</para> </para>
<Para> <para>
The possible response messages from the backend are: The possible response messages from the backend are:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term>CommandComplete</Term> <term>CommandComplete</term>
<ListItem> <listitem>
<Para> <para>
An SQL command completed normally. An SQL command completed normally.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>CopyInResponse</Term> <term>CopyInResponse</term>
<ListItem> <listitem>
<Para> <para>
The backend is ready to copy data from the frontend to a The backend is ready to copy data from the frontend to a
table; see <xref linkend="protocol-copy">. table; see <xref linkend="protocol-copy">.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>CopyOutResponse</Term> <term>CopyOutResponse</term>
<ListItem> <listitem>
<Para> <para>
The backend is ready to copy data from a table to the The backend is ready to copy data from a table to the
frontend; see <xref linkend="protocol-copy">. frontend; see <xref linkend="protocol-copy">.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>RowDescription</Term> <term>RowDescription</term>
<ListItem> <listitem>
<Para> <para>
Indicates that rows are about to be returned in response to Indicates that rows are about to be returned in response to
a <command>SELECT</command>, <command>FETCH</command>, etc query. a <command>SELECT</command>, <command>FETCH</command>, etc query.
The contents of this message describe the column layout of the rows. The contents of this message describe the column layout of the rows.
This will be followed by a DataRow message for each row being returned This will be followed by a DataRow message for each row being returned
to the frontend. to the frontend.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>DataRow</Term> <term>DataRow</term>
<ListItem> <listitem>
<Para> <para>
One of the set of rows returned by One of the set of rows returned by
a <command>SELECT</command>, <command>FETCH</command>, etc query. a <command>SELECT</command>, <command>FETCH</command>, etc query.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>EmptyQueryResponse</Term> <term>EmptyQueryResponse</term>
<ListItem> <listitem>
<Para> <para>
An empty query string was recognized. An empty query string was recognized.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>ErrorResponse</Term> <term>ErrorResponse</term>
<ListItem> <listitem>
<Para> <para>
An error has occurred. An error has occurred.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>ReadyForQuery</Term> <term>ReadyForQuery</term>
<ListItem> <listitem>
<Para> <para>
Processing of the query string is complete. A separate Processing of the query string is complete. A separate
message is sent to indicate this because the query string may message is sent to indicate this because the query string may
contain multiple SQL commands. (CommandComplete marks the contain multiple SQL commands. (CommandComplete marks the
end of processing one SQL command, not the whole string.) end of processing one SQL command, not the whole string.)
ReadyForQuery will always be sent, whether processing ReadyForQuery will always be sent, whether processing
terminates successfully or with an error. terminates successfully or with an error.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>NoticeResponse</Term> <term>NoticeResponse</term>
<ListItem> <listitem>
<Para> <para>
A warning message has been issued in relation to the query. A warning message has been issued in relation to the query.
Notices are in addition to other responses, i.e., the backend Notices are in addition to other responses, i.e., the backend
will continue processing the command. will continue processing the command.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
<Para> <para>
The response to a <command>SELECT</> query (or other queries that The response to a <command>SELECT</> query (or other queries that
return row sets, such as <command>EXPLAIN</> or <command>SHOW</>) return row sets, such as <command>EXPLAIN</> or <command>SHOW</>)
normally consists of RowDescription, zero or more normally consists of RowDescription, zero or more
...@@ -570,28 +570,28 @@ ...@@ -570,28 +570,28 @@
as described in <xref linkend="protocol-copy">. as described in <xref linkend="protocol-copy">.
All other query types normally produce only All other query types normally produce only
a CommandComplete message. a CommandComplete message.
</Para> </para>
<Para> <para>
Since a query string could contain several queries (separated by Since a query string could contain several queries (separated by
semicolons), there might be several such response sequences before the semicolons), there might be several such response sequences before the
backend finishes processing the query string. ReadyForQuery is issued backend finishes processing the query string. ReadyForQuery is issued
when the entire string has been processed and the backend is ready to when the entire string has been processed and the backend is ready to
accept a new query string. accept a new query string.
</Para> </para>
<Para> <para>
If a completely empty (no contents other than whitespace) query string If a completely empty (no contents other than whitespace) query string
is received, the response is EmptyQueryResponse followed by ReadyForQuery. is received, the response is EmptyQueryResponse followed by ReadyForQuery.
</Para> </para>
<Para> <para>
In the event of an error, ErrorResponse is issued followed by In the event of an error, ErrorResponse is issued followed by
ReadyForQuery. All further processing of the query string is aborted by ReadyForQuery. All further processing of the query string is aborted by
ErrorResponse (even if more queries remained in it). Note that this ErrorResponse (even if more queries remained in it). Note that this
may occur partway through the sequence of messages generated by an may occur partway through the sequence of messages generated by an
individual query. individual query.
</Para> </para>
<para> <para>
In simple Query mode, the format of retrieved values is always text, In simple Query mode, the format of retrieved values is always text,
...@@ -615,8 +615,8 @@ ...@@ -615,8 +615,8 @@
</para> </para>
</sect2> </sect2>
<Sect2> <sect2>
<Title>Extended Query</Title> <title>Extended Query</title>
<para> <para>
The extended query protocol breaks down the above-described simple The extended query protocol breaks down the above-described simple
...@@ -854,8 +854,8 @@ ...@@ -854,8 +854,8 @@
</note> </note>
</sect2> </sect2>
<Sect2> <sect2>
<Title>Function Call</Title> <title>Function Call</title>
<para> <para>
The Function Call sub-protocol allows the client to request a direct The Function Call sub-protocol allows the client to request a direct
...@@ -885,51 +885,51 @@ ...@@ -885,51 +885,51 @@
<para> <para>
The possible response messages from the backend are: The possible response messages from the backend are:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term>ErrorResponse</Term> <term>ErrorResponse</term>
<ListItem> <listitem>
<Para> <para>
An error has occurred. An error has occurred.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>FunctionCallResponse</Term> <term>FunctionCallResponse</term>
<ListItem> <listitem>
<Para> <para>
The function call was completed and returned the result given The function call was completed and returned the result given
in the message. in the message.
(Note that the Function Call protocol can only handle a single (Note that the Function Call protocol can only handle a single
scalar result, not a row type or set of results.) scalar result, not a row type or set of results.)
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>ReadyForQuery</Term> <term>ReadyForQuery</term>
<ListItem> <listitem>
<Para> <para>
Processing of the function call is complete. ReadyForQuery Processing of the function call is complete. ReadyForQuery
will always be sent, whether processing terminates will always be sent, whether processing terminates
successfully or with an error. successfully or with an error.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term>NoticeResponse</Term> <term>NoticeResponse</term>
<ListItem> <listitem>
<Para> <para>
A warning message has been issued in relation to the function A warning message has been issued in relation to the function
call. Notices are in addition to other responses, i.e., the call. Notices are in addition to other responses, i.e., the
backend will continue processing the command. backend will continue processing the command.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</sect2> </sect2>
<sect2 id="protocol-copy"> <sect2 id="protocol-copy">
...@@ -1086,10 +1086,10 @@ ...@@ -1086,10 +1086,10 @@
</note> </note>
</sect2> </sect2>
<Sect2> <sect2>
<Title>Cancelling Requests in Progress</Title> <title>Cancelling Requests in Progress</title>
<Para> <para>
During the processing of a query, the frontend may request During the processing of a query, the frontend may request
cancellation of the query. The cancel request is not sent cancellation of the query. The cancel request is not sent
directly on the open connection to the backend for reasons of directly on the open connection to the backend for reasons of
...@@ -1100,7 +1100,7 @@ ...@@ -1100,7 +1100,7 @@
the normal case. the normal case.
</para> </para>
<Para> <para>
To issue a cancel request, the frontend opens a new connection to To issue a cancel request, the frontend opens a new connection to
the server and sends a CancelRequest message, rather than the the server and sends a CancelRequest message, rather than the
StartupMessage message that would ordinarily be sent across a new StartupMessage message that would ordinarily be sent across a new
...@@ -1109,7 +1109,7 @@ ...@@ -1109,7 +1109,7 @@
the cancel request message. the cancel request message.
</para> </para>
<Para> <para>
A CancelRequest message will be ignored unless it contains the A CancelRequest message will be ignored unless it contains the
same key data (PID and secret key) passed to the frontend during same key data (PID and secret key) passed to the frontend during
connection start-up. If the request matches the PID and secret connection start-up. If the request matches the PID and secret
...@@ -1119,7 +1119,7 @@ ...@@ -1119,7 +1119,7 @@
processing the query.) processing the query.)
</para> </para>
<Para> <para>
The cancellation signal may or may not have any effect &mdash; for The cancellation signal may or may not have any effect &mdash; for
example, if it arrives after the backend has finished processing example, if it arrives after the backend has finished processing
the query, then it will have no effect. If the cancellation is the query, then it will have no effect. If the cancellation is
...@@ -1127,7 +1127,7 @@ ...@@ -1127,7 +1127,7 @@
early with an error message. early with an error message.
</para> </para>
<Para> <para>
The upshot of all this is that for reasons of both security and The upshot of all this is that for reasons of both security and
efficiency, the frontend has no direct way to tell whether a efficiency, the frontend has no direct way to tell whether a
cancel request has succeeded. It must continue to wait for the cancel request has succeeded. It must continue to wait for the
...@@ -1137,7 +1137,7 @@ ...@@ -1137,7 +1137,7 @@
succeeding. succeeding.
</para> </para>
<Para> <para>
Since the cancel request is sent across a new connection to the Since the cancel request is sent across a new connection to the
server and not across the regular frontend/backend communication server and not across the regular frontend/backend communication
link, it is possible for the cancel request to be issued by any link, it is possible for the cancel request to be issued by any
...@@ -1150,8 +1150,8 @@ ...@@ -1150,8 +1150,8 @@
</para> </para>
</sect2> </sect2>
<Sect2> <sect2>
<Title>Termination</Title> <title>Termination</title>
<para> <para>
The normal, graceful termination procedure is that the frontend The normal, graceful termination procedure is that the frontend
...@@ -1190,10 +1190,10 @@ ...@@ -1190,10 +1190,10 @@
</para> </para>
</sect2> </sect2>
<Sect2> <sect2>
<Title><acronym>SSL</acronym> Session Encryption</Title> <title><acronym>SSL</acronym> Session Encryption</title>
<Para> <para>
If <productname>PostgreSQL</> was built with If <productname>PostgreSQL</> was built with
<acronym>SSL</acronym> support, frontend/backend communications <acronym>SSL</acronym> support, frontend/backend communications
can be encrypted using <acronym>SSL</acronym>. This provides can be encrypted using <acronym>SSL</acronym>. This provides
...@@ -1244,92 +1244,92 @@ ...@@ -1244,92 +1244,92 @@
</sect2> </sect2>
</sect1> </sect1>
<Sect1 id="protocol-message-types"> <sect1 id="protocol-message-types">
<Title>Message Data Types</Title> <title>Message Data Types</title>
<Para> <para>
This section describes the base data types used in messages. This section describes the base data types used in messages.
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int<Replaceable>n</Replaceable>(<Replaceable>i</Replaceable>) Int<replaceable>n</replaceable>(<replaceable>i</replaceable>)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
An <Replaceable>n</Replaceable>-bit integer in network byte An <replaceable>n</replaceable>-bit integer in network byte
order (most significant byte first). order (most significant byte first).
If <Replaceable>i</Replaceable> is specified it If <replaceable>i</replaceable> is specified it
is the exact value that will appear, otherwise the value is the exact value that will appear, otherwise the value
is variable. Eg. Int16, Int32(42). is variable. Eg. Int16, Int32(42).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int<Replaceable>n</Replaceable>[<Replaceable>k</Replaceable>] Int<replaceable>n</replaceable>[<replaceable>k</replaceable>]
</Term> </term>
<ListItem> <listitem>
<Para> <para>
An array of <Replaceable>k</Replaceable> An array of <replaceable>k</replaceable>
<Replaceable>n</Replaceable>-bit integers, each in network <replaceable>n</replaceable>-bit integers, each in network
byte order. The array length <Replaceable>k</Replaceable> byte order. The array length <replaceable>k</replaceable>
is always determined by an earlier field in the message. is always determined by an earlier field in the message.
Eg. Int16[M]. Eg. Int16[M].
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String(<Replaceable>s</Replaceable>) String(<replaceable>s</replaceable>)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
A null-terminated string (C-style string). There is no A null-terminated string (C-style string). There is no
specific length limitation on strings. specific length limitation on strings.
If <Replaceable>s</Replaceable> is specified it is the exact If <replaceable>s</replaceable> is specified it is the exact
value that will appear, otherwise the value is variable. value that will appear, otherwise the value is variable.
Eg. String, String("user"). Eg. String, String("user").
</Para> </para>
<Note> <note>
<Para> <para>
<Emphasis>There is no predefined limit</Emphasis> on the length of a string <emphasis>There is no predefined limit</emphasis> on the length of a string
that can be returned by the backend. Good coding strategy for a frontend that can be returned by the backend. Good coding strategy for a frontend
is to use an expandable buffer so that anything that fits in memory can be is to use an expandable buffer so that anything that fits in memory can be
accepted. If that's not feasible, read the full string and discard trailing accepted. If that's not feasible, read the full string and discard trailing
characters that don't fit into your fixed-size buffer. characters that don't fit into your fixed-size buffer.
</Para> </para>
</Note> </note>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte<Replaceable>n</Replaceable>(<Replaceable>c</Replaceable>) Byte<replaceable>n</replaceable>(<replaceable>c</replaceable>)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Exactly <Replaceable>n</Replaceable> bytes. If the field Exactly <replaceable>n</replaceable> bytes. If the field
width <Replaceable>n</Replaceable> is not a constant, it is width <replaceable>n</replaceable> is not a constant, it is
always determinable from an earlier field in the message. always determinable from an earlier field in the message.
If <Replaceable>c</Replaceable> is specified it is the exact If <replaceable>c</replaceable> is specified it is the exact
value. Eg. Byte2, Byte1('\n'). value. Eg. Byte2, Byte1('\n').
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</sect1> </sect1>
<Sect1 id="protocol-message-formats"> <sect1 id="protocol-message-formats">
<Title>Message Formats</Title> <title>Message Formats</title>
<Para> <para>
This section describes the detailed format of each message. Each is marked to This section describes the detailed format of each message. Each is marked to
indicate that it may be sent by a frontend (F), a backend (B), or both indicate that it may be sent by a frontend (F), a backend (B), or both
(F &amp; B). (F &amp; B).
...@@ -1340,454 +1340,454 @@ message is an exception, because it forms part of a data stream; the contents ...@@ -1340,454 +1340,454 @@ message is an exception, because it forms part of a data stream; the contents
of any individual CopyData message may not be interpretable on their own.) of any individual CopyData message may not be interpretable on their own.)
</para> </para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
AuthenticationOk (B) AuthenticationOk (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('R') Byte1('R')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as an authentication request. Identifies the message as an authentication request.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(8) Int32(8)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(0) Int32(0)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies that the authentication was successful. Specifies that the authentication was successful.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
AuthenticationKerberosV4 (B) AuthenticationKerberosV4 (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('R') Byte1('R')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as an authentication request. Identifies the message as an authentication request.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(8) Int32(8)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(1) Int32(1)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies that Kerberos V4 authentication is required. Specifies that Kerberos V4 authentication is required.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
AuthenticationKerberosV5 (B) AuthenticationKerberosV5 (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('R') Byte1('R')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as an authentication request. Identifies the message as an authentication request.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(8) Int32(8)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(2) Int32(2)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies that Kerberos V5 authentication is required. Specifies that Kerberos V5 authentication is required.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
AuthenticationCleartextPassword (B) AuthenticationCleartextPassword (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('R') Byte1('R')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as an authentication request. Identifies the message as an authentication request.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(8) Int32(8)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(3) Int32(3)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies that a clear-text password is required. Specifies that a clear-text password is required.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
AuthenticationCryptPassword (B) AuthenticationCryptPassword (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('R') Byte1('R')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as an authentication request. Identifies the message as an authentication request.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(10) Int32(10)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies that a crypt()-encrypted password is required. Specifies that a crypt()-encrypted password is required.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte2 Byte2
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The salt to use when encrypting the password. The salt to use when encrypting the password.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
AuthenticationMD5Password (B) AuthenticationMD5Password (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('R') Byte1('R')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as an authentication request. Identifies the message as an authentication request.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(12) Int32(12)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(5) Int32(5)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies that an MD5-encrypted password is required. Specifies that an MD5-encrypted password is required.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte4 Byte4
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The salt to use when encrypting the password. The salt to use when encrypting the password.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
AuthenticationSCMCredential (B) AuthenticationSCMCredential (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('R') Byte1('R')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as an authentication request. Identifies the message as an authentication request.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(8) Int32(8)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(6) Int32(6)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies that an SCM credentials message is required. Specifies that an SCM credentials message is required.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
BackendKeyData (B) BackendKeyData (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('K') Byte1('K')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as cancellation key data. Identifies the message as cancellation key data.
The frontend must save these values if it wishes to be The frontend must save these values if it wishes to be
able to issue CancelRequest messages later. able to issue CancelRequest messages later.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(12) Int32(12)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The process ID of this backend. The process ID of this backend.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The secret key of this backend. The secret key of this backend.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Bind (F) Bind (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('B') Byte1('B')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Bind command. Identifies the message as a Bind command.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The name of the destination portal The name of the destination portal
(an empty string selects the unnamed portal). (an empty string selects the unnamed portal).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The name of the source prepared statement The name of the source prepared statement
(an empty string selects the unnamed prepared statement). (an empty string selects the unnamed prepared statement).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The number of parameter format codes that follow The number of parameter format codes that follow
(denoted <replaceable>C</> below). (denoted <replaceable>C</> below).
This can be zero to indicate that there are no parameters This can be zero to indicate that there are no parameters
...@@ -1795,68 +1795,68 @@ Bind (F) ...@@ -1795,68 +1795,68 @@ Bind (F)
or one, in which case the specified format code is applied or one, in which case the specified format code is applied
to all parameters; or it can equal the actual number of to all parameters; or it can equal the actual number of
parameters. parameters.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16[<replaceable>C</>] Int16[<replaceable>C</>]
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The parameter format codes. Each must presently be The parameter format codes. Each must presently be
zero (text) or one (binary). zero (text) or one (binary).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The number of parameter values that follow (possibly zero). The number of parameter values that follow (possibly zero).
This must match the number of parameters needed by the query. This must match the number of parameters needed by the query.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
Next, the following pair of fields appear for each parameter: Next, the following pair of fields appear for each parameter:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The length of the parameter value, in bytes (this count The length of the parameter value, in bytes (this count
does not include itself). Can be zero. does not include itself). Can be zero.
As a special case, -1 indicates a NULL parameter value. As a special case, -1 indicates a NULL parameter value.
No value bytes follow in the NULL case. No value bytes follow in the NULL case.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte<Replaceable>n</Replaceable> Byte<replaceable>n</replaceable>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The value of the parameter, in the format indicated by the The value of the parameter, in the format indicated by the
associated format code. associated format code.
<Replaceable>n</Replaceable> is the above length. <replaceable>n</replaceable> is the above length.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
After the last parameter, the following fields appear: After the last parameter, the following fields appear:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The number of result-column format codes that follow The number of result-column format codes that follow
(denoted <replaceable>R</> below). (denoted <replaceable>R</> below).
This can be zero to indicate that there are no result columns This can be zero to indicate that there are no result columns
...@@ -1865,271 +1865,271 @@ Bind (F) ...@@ -1865,271 +1865,271 @@ Bind (F)
or one, in which case the specified format code is applied or one, in which case the specified format code is applied
to all result columns (if any); or it can equal the actual to all result columns (if any); or it can equal the actual
number of result columns of the query. number of result columns of the query.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16[<replaceable>R</>] Int16[<replaceable>R</>]
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The result-column format codes. Each must presently be The result-column format codes. Each must presently be
zero (text) or one (binary). zero (text) or one (binary).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
BindComplete (B) BindComplete (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('2') Byte1('2')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Bind-complete indicator. Identifies the message as a Bind-complete indicator.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
CancelRequest (F) CancelRequest (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(16) Int32(16)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(80877102) Int32(80877102)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The cancel request code. The value is chosen to contain The cancel request code. The value is chosen to contain
<literal>1234</> in the most significant 16 bits, and <literal>5678</> in the <literal>1234</> in the most significant 16 bits, and <literal>5678</> in the
least 16 significant bits. (To avoid confusion, this code least 16 significant bits. (To avoid confusion, this code
must not be the same as any protocol version number.) must not be the same as any protocol version number.)
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The process ID of the target backend. The process ID of the target backend.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The secret key for the target backend. The secret key for the target backend.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Close (F) Close (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('C') Byte1('C')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Close command. Identifies the message as a Close command.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1 Byte1
</Term> </term>
<ListItem> <listitem>
<Para> <para>
'<literal>S</>' to close a prepared statement; or '<literal>S</>' to close a prepared statement; or
'<literal>P</>' to close a portal. '<literal>P</>' to close a portal.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The name of the prepared statement or portal to close The name of the prepared statement or portal to close
(an empty string selects the unnamed prepared statement (an empty string selects the unnamed prepared statement
or portal). or portal).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
CloseComplete (B) CloseComplete (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('3') Byte1('3')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Close-complete indicator. Identifies the message as a Close-complete indicator.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
CommandComplete (B) CommandComplete (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('C') Byte1('C')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a command-completed response. Identifies the message as a command-completed response.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The command tag. This is usually a single The command tag. This is usually a single
word that identifies which SQL command was completed. word that identifies which SQL command was completed.
</Para> </para>
<Para> <para>
For an <command>INSERT</command> command, the tag is For an <command>INSERT</command> command, the tag is
<literal>INSERT <replaceable>oid</replaceable> <literal>INSERT <replaceable>oid</replaceable>
<replaceable>rows</replaceable></literal>, where <replaceable>rows</replaceable></literal>, where
<replaceable>rows</replaceable> is the number of rows <replaceable>rows</replaceable> is the number of rows
inserted. <replaceable>oid</replaceable> is the object ID inserted. <replaceable>oid</replaceable> is the object ID
of the inserted row if <Replaceable>rows</Replaceable> is 1 of the inserted row if <replaceable>rows</replaceable> is 1
and the target table has OIDs; and the target table has OIDs;
otherwise <Replaceable>oid</Replaceable> is 0. otherwise <replaceable>oid</replaceable> is 0.
</Para> </para>
<Para> <para>
For a <command>DELETE</command> command, the tag is For a <command>DELETE</command> command, the tag is
<literal>DELETE <Replaceable>rows</Replaceable></literal> where <literal>DELETE <replaceable>rows</replaceable></literal> where
<Replaceable>rows</Replaceable> is the number of rows deleted. <replaceable>rows</replaceable> is the number of rows deleted.
</Para> </para>
<Para> <para>
For an <command>UPDATE</command> command, the tag is For an <command>UPDATE</command> command, the tag is
<literal>UPDATE <Replaceable>rows</Replaceable></literal> where <literal>UPDATE <replaceable>rows</replaceable></literal> where
<Replaceable>rows</Replaceable> is the number of rows updated. <replaceable>rows</replaceable> is the number of rows updated.
</Para> </para>
<para> <para>
For a <command>MOVE</command> command, the tag is For a <command>MOVE</command> command, the tag is
...@@ -2143,178 +2143,178 @@ CommandComplete (B) ...@@ -2143,178 +2143,178 @@ CommandComplete (B)
<literal>FETCH <replaceable>rows</replaceable></literal> where <literal>FETCH <replaceable>rows</replaceable></literal> where
<replaceable>rows</replaceable> is the number of rows that <replaceable>rows</replaceable> is the number of rows that
have been retrieved from the cursor. have been retrieved from the cursor.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
CopyData (F &amp; B) CopyData (F &amp; B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('d') Byte1('d')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as <command>COPY</command> data. Identifies the message as <command>COPY</command> data.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte<Replaceable>n</Replaceable> Byte<replaceable>n</replaceable>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Data that forms part of a <command>COPY</command> data stream. Messages sent Data that forms part of a <command>COPY</command> data stream. Messages sent
from the backend will always correspond to single data rows, from the backend will always correspond to single data rows,
but messages sent by frontends may divide the data stream but messages sent by frontends may divide the data stream
arbitrarily. arbitrarily.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
CopyDone (F &amp; B) CopyDone (F &amp; B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('c') Byte1('c')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a <command>COPY</command>-complete indicator. Identifies the message as a <command>COPY</command>-complete indicator.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
CopyFail (F) CopyFail (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('f') Byte1('f')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a <command>COPY</command>-failure indicator. Identifies the message as a <command>COPY</command>-failure indicator.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
An error message to report as the cause of failure. An error message to report as the cause of failure.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
CopyInResponse (B) CopyInResponse (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('G') Byte1('G')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Start Copy In response. Identifies the message as a Start Copy In response.
The frontend must now send copy-in data (if not The frontend must now send copy-in data (if not
prepared to do so, send a CopyFail message). prepared to do so, send a CopyFail message).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int8 Int8
</Term> </term>
<ListItem> <listitem>
<Para> <para>
0 indicates the overall <command>COPY</command> format is textual (rows 0 indicates the overall <command>COPY</command> format is textual (rows
separated by newlines, columns separated by separator separated by newlines, columns separated by separator
characters, etc). characters, etc).
...@@ -2322,317 +2322,317 @@ CopyInResponse (B) ...@@ -2322,317 +2322,317 @@ CopyInResponse (B)
to DataRow format). to DataRow format).
See <xref linkend="sql-copy" endterm="sql-copy-title"> See <xref linkend="sql-copy" endterm="sql-copy-title">
for more information. for more information.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The number of columns in the data to be copied The number of columns in the data to be copied
(denoted <replaceable>N</> below). (denoted <replaceable>N</> below).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16[<replaceable>N</>] Int16[<replaceable>N</>]
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The format codes to be used for each column. The format codes to be used for each column.
Each must presently be zero (text) or one (binary). Each must presently be zero (text) or one (binary).
All must be zero if the overall copy format is textual. All must be zero if the overall copy format is textual.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
CopyOutResponse (B) CopyOutResponse (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('H') Byte1('H')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Start Copy Out response. Identifies the message as a Start Copy Out response.
This message will be followed by copy-out data. This message will be followed by copy-out data.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int8 Int8
</Term> </term>
<ListItem> <listitem>
<Para> <para>
0 indicates the overall <command>COPY</command> format 0 indicates the overall <command>COPY</command> format
is textual (rows separated by newlines, columns is textual (rows separated by newlines, columns
separated by separator characters, etc). 1 indicates separated by separator characters, etc). 1 indicates
the overall copy format is binary (similar to DataRow the overall copy format is binary (similar to DataRow
format). See <xref linkend="sql-copy" format). See <xref linkend="sql-copy"
endterm="sql-copy-title"> for more information. endterm="sql-copy-title"> for more information.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The number of columns in the data to be copied The number of columns in the data to be copied
(denoted <replaceable>N</> below). (denoted <replaceable>N</> below).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16[<replaceable>N</>] Int16[<replaceable>N</>]
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The format codes to be used for each column. The format codes to be used for each column.
Each must presently be zero (text) or one (binary). Each must presently be zero (text) or one (binary).
All must be zero if the overall copy format is textual. All must be zero if the overall copy format is textual.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
DataRow (B) DataRow (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('D') Byte1('D')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a data row. Identifies the message as a data row.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The number of column values that follow (possibly zero). The number of column values that follow (possibly zero).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
Next, the following pair of fields appear for each column: Next, the following pair of fields appear for each column:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The length of the column value, in bytes (this count The length of the column value, in bytes (this count
does not include itself). Can be zero. does not include itself). Can be zero.
As a special case, -1 indicates a NULL column value. As a special case, -1 indicates a NULL column value.
No value bytes follow in the NULL case. No value bytes follow in the NULL case.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte<Replaceable>n</Replaceable> Byte<replaceable>n</replaceable>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The value of the column, in the format indicated by the The value of the column, in the format indicated by the
associated format code. associated format code.
<Replaceable>n</Replaceable> is the above length. <replaceable>n</replaceable> is the above length.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Describe (F) Describe (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('D') Byte1('D')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Describe command. Identifies the message as a Describe command.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1 Byte1
</Term> </term>
<ListItem> <listitem>
<Para> <para>
'<literal>S</>' to describe a prepared statement; or '<literal>S</>' to describe a prepared statement; or
'<literal>P</>' to describe a portal. '<literal>P</>' to describe a portal.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The name of the prepared statement or portal to describe The name of the prepared statement or portal to describe
(an empty string selects the unnamed prepared statement (an empty string selects the unnamed prepared statement
or portal). or portal).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
EmptyQueryResponse (B) EmptyQueryResponse (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('I') Byte1('I')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a response to an empty query string. Identifies the message as a response to an empty query string.
(This substitutes for CommandComplete.) (This substitutes for CommandComplete.)
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
ErrorResponse (B) ErrorResponse (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('E') Byte1('E')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as an error. Identifies the message as an error.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
The message body consists of one or more identified fields, The message body consists of one or more identified fields,
followed by a zero byte as a terminator. Fields may appear in followed by a zero byte as a terminator. Fields may appear in
any order. For each field there is the following: any order. For each field there is the following:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1 Byte1
</Term> </term>
<ListItem> <listitem>
<Para> <para>
A code identifying the field type; if zero, this is A code identifying the field type; if zero, this is
the message terminator and no string follows. the message terminator and no string follows.
The presently defined field types are listed in The presently defined field types are listed in
...@@ -2640,162 +2640,162 @@ ErrorResponse (B) ...@@ -2640,162 +2640,162 @@ ErrorResponse (B)
Since more field types may be added in future, Since more field types may be added in future,
frontends should silently ignore fields of unrecognized frontends should silently ignore fields of unrecognized
type. type.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The field value. The field value.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Execute (F) Execute (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('E') Byte1('E')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as an Execute command. Identifies the message as an Execute command.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The name of the portal to execute The name of the portal to execute
(an empty string selects the unnamed portal). (an empty string selects the unnamed portal).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Maximum number of rows to return, if portal contains Maximum number of rows to return, if portal contains
a query that returns rows (ignored otherwise). Zero a query that returns rows (ignored otherwise). Zero
denotes <quote>no limit</>. denotes <quote>no limit</>.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Flush (F) Flush (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('H') Byte1('H')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Flush command. Identifies the message as a Flush command.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
FunctionCall (F) FunctionCall (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('F') Byte1('F')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a function call. Identifies the message as a function call.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies the object ID of the function to call. Specifies the object ID of the function to call.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The number of argument format codes that follow The number of argument format codes that follow
(denoted <replaceable>C</> below). (denoted <replaceable>C</> below).
This can be zero to indicate that there are no arguments This can be zero to indicate that there are no arguments
...@@ -2803,214 +2803,214 @@ FunctionCall (F) ...@@ -2803,214 +2803,214 @@ FunctionCall (F)
or one, in which case the specified format code is applied or one, in which case the specified format code is applied
to all arguments; or it can equal the actual number of to all arguments; or it can equal the actual number of
arguments. arguments.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16[<replaceable>C</>] Int16[<replaceable>C</>]
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The argument format codes. Each must presently be The argument format codes. Each must presently be
zero (text) or one (binary). zero (text) or one (binary).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies the number of arguments being supplied to the Specifies the number of arguments being supplied to the
function. function.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
Next, the following pair of fields appear for each argument: Next, the following pair of fields appear for each argument:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The length of the argument value, in bytes (this count The length of the argument value, in bytes (this count
does not include itself). Can be zero. does not include itself). Can be zero.
As a special case, -1 indicates a NULL argument value. As a special case, -1 indicates a NULL argument value.
No value bytes follow in the NULL case. No value bytes follow in the NULL case.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte<Replaceable>n</Replaceable> Byte<replaceable>n</replaceable>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The value of the argument, in the format indicated by the The value of the argument, in the format indicated by the
associated format code. associated format code.
<Replaceable>n</Replaceable> is the above length. <replaceable>n</replaceable> is the above length.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
After the last argument, the following field appears: After the last argument, the following field appears:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The format code for the function result. Must presently be The format code for the function result. Must presently be
zero (text) or one (binary). zero (text) or one (binary).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
FunctionCallResponse (B) FunctionCallResponse (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('V') Byte1('V')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a function call result. Identifies the message as a function call result.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The length of the function result value, in bytes (this count The length of the function result value, in bytes (this count
does not include itself). Can be zero. does not include itself). Can be zero.
As a special case, -1 indicates a NULL function result. As a special case, -1 indicates a NULL function result.
No value bytes follow in the NULL case. No value bytes follow in the NULL case.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte<Replaceable>n</Replaceable> Byte<replaceable>n</replaceable>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The value of the function result, in the format indicated by The value of the function result, in the format indicated by
the associated format code. the associated format code.
<Replaceable>n</Replaceable> is the above length. <replaceable>n</replaceable> is the above length.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
NoData (B) NoData (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('n') Byte1('n')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a no-data indicator. Identifies the message as a no-data indicator.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
NoticeResponse (B) NoticeResponse (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('N') Byte1('N')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a notice. Identifies the message as a notice.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
The message body consists of one or more identified fields, The message body consists of one or more identified fields,
followed by a zero byte as a terminator. Fields may appear in followed by a zero byte as a terminator. Fields may appear in
any order. For each field there is the following: any order. For each field there is the following:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1 Byte1
</Term> </term>
<ListItem> <listitem>
<Para> <para>
A code identifying the field type; if zero, this is A code identifying the field type; if zero, this is
the message terminator and no string follows. the message terminator and no string follows.
The presently defined field types are listed in The presently defined field types are listed in
...@@ -3018,848 +3018,848 @@ NoticeResponse (B) ...@@ -3018,848 +3018,848 @@ NoticeResponse (B)
Since more field types may be added in future, Since more field types may be added in future,
frontends should silently ignore fields of unrecognized frontends should silently ignore fields of unrecognized
type. type.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The field value. The field value.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
NotificationResponse (B) NotificationResponse (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('A') Byte1('A')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a notification response. Identifies the message as a notification response.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The process ID of the notifying backend process. The process ID of the notifying backend process.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The name of the condition that the notify has been raised on. The name of the condition that the notify has been raised on.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Additional information passed from the notifying process. Additional information passed from the notifying process.
(Currently, this feature is unimplemented so the field (Currently, this feature is unimplemented so the field
is always an empty string.) is always an empty string.)
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
ParameterDescription (B) ParameterDescription (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('t') Byte1('t')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a parameter description. Identifies the message as a parameter description.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The number of parameters used by the statement The number of parameters used by the statement
(may be zero). (may be zero).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
Then, for each parameter, there is the following: Then, for each parameter, there is the following:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies the object ID of the parameter data type. Specifies the object ID of the parameter data type.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
ParameterStatus (B) ParameterStatus (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('S') Byte1('S')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a run-time parameter status report. Identifies the message as a run-time parameter status report.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The name of the run-time parameter being reported. The name of the run-time parameter being reported.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The current value of the parameter. The current value of the parameter.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Parse (F) Parse (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('P') Byte1('P')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Parse command. Identifies the message as a Parse command.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The name of the destination prepared statement The name of the destination prepared statement
(an empty string selects the unnamed prepared statement). (an empty string selects the unnamed prepared statement).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The query string to be parsed. The query string to be parsed.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The number of parameter data types specified The number of parameter data types specified
(may be zero). Note that this is not an indication of (may be zero). Note that this is not an indication of
the number of parameters that might appear in the the number of parameters that might appear in the
query string, only the number that the frontend wants to query string, only the number that the frontend wants to
prespecify types for. prespecify types for.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
Then, for each parameter, there is the following: Then, for each parameter, there is the following:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies the object ID of the parameter data type. Specifies the object ID of the parameter data type.
Placing a zero here is equivalent to leaving the type Placing a zero here is equivalent to leaving the type
unspecified. unspecified.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
ParseComplete (B) ParseComplete (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('1') Byte1('1')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Parse-complete indicator. Identifies the message as a Parse-complete indicator.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
PasswordMessage (F) PasswordMessage (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('p') Byte1('p')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a password response. Identifies the message as a password response.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The password (encrypted, if requested). The password (encrypted, if requested).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
PortalSuspended (B) PortalSuspended (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('s') Byte1('s')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a portal-suspended indicator. Identifies the message as a portal-suspended indicator.
Note this only appears if an Execute message's row-count limit Note this only appears if an Execute message's row-count limit
was reached. was reached.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Query (F) Query (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('Q') Byte1('Q')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a simple query. Identifies the message as a simple query.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The query string itself. The query string itself.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
ReadyForQuery (B) ReadyForQuery (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('Z') Byte1('Z')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message type. ReadyForQuery is sent Identifies the message type. ReadyForQuery is sent
whenever the backend is ready for a new query cycle. whenever the backend is ready for a new query cycle.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(5) Int32(5)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1 Byte1
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Current backend transaction status indicator. Current backend transaction status indicator.
Possible values are '<literal>I</>' if idle (not in Possible values are '<literal>I</>' if idle (not in
a transaction block); '<literal>T</>' if in a transaction a transaction block); '<literal>T</>' if in a transaction
block; or '<literal>E</>' if in a failed transaction block; or '<literal>E</>' if in a failed transaction
block (queries will be rejected until block is ended). block (queries will be rejected until block is ended).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
RowDescription (B) RowDescription (B)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('T') Byte1('T')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a row description. Identifies the message as a row description.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Specifies the number of fields in a row (may be zero). Specifies the number of fields in a row (may be zero).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
Then, for each field, there is the following: Then, for each field, there is the following:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The field name. The field name.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
If the field can be identified as a column of a specific If the field can be identified as a column of a specific
table, the object ID of the table; otherwise zero. table, the object ID of the table; otherwise zero.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
If the field can be identified as a column of a specific If the field can be identified as a column of a specific
table, the attribute number of the column; otherwise zero. table, the attribute number of the column; otherwise zero.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The object ID of the field's data type. The object ID of the field's data type.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The data type size (see <varname>pg_type.typlen</>). The data type size (see <varname>pg_type.typlen</>).
Note that negative values denote variable-width types. Note that negative values denote variable-width types.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The type modifier (see <varname>pg_attribute.atttypmod</>). The type modifier (see <varname>pg_attribute.atttypmod</>).
The meaning of the modifier is type-specific. The meaning of the modifier is type-specific.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int16 Int16
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The format code being used for the field. Currently will The format code being used for the field. Currently will
be zero (text) or one (binary). In a RowDescription be zero (text) or one (binary). In a RowDescription
returned from the statement variant of Describe, the returned from the statement variant of Describe, the
format code is not yet known and will always be zero. format code is not yet known and will always be zero.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
SSLRequest (F) SSLRequest (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(8) Int32(8)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(80877103) Int32(80877103)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The <acronym>SSL</acronym> request code. The value is chosen to contain The <acronym>SSL</acronym> request code. The value is chosen to contain
<literal>1234</> in the most significant 16 bits, and <literal>5679</> in the <literal>1234</> in the most significant 16 bits, and <literal>5679</> in the
least 16 significant bits. (To avoid confusion, this code least 16 significant bits. (To avoid confusion, this code
must not be the same as any protocol version number.) must not be the same as any protocol version number.)
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
StartupMessage (F) StartupMessage (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Int32 Int32
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(196608) Int32(196608)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The protocol version number. The most significant 16 bits are The protocol version number. The most significant 16 bits are
the major version number (3 for the protocol described here). the major version number (3 for the protocol described here).
The least significant 16 bits are the minor version number The least significant 16 bits are the minor version number
(0 for the protocol described here). (0 for the protocol described here).
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
The protocol version number is followed by one or more pairs of The protocol version number is followed by one or more pairs of
parameter name and value strings. A zero byte is required as a parameter name and value strings. A zero byte is required as a
terminator after the last name/value pair. terminator after the last name/value pair.
Parameters can appear in any Parameters can appear in any
order. <literal>user</> is required, others are optional. order. <literal>user</> is required, others are optional.
Each parameter is specified as: Each parameter is specified as:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The parameter name. Currently recognized names are: The parameter name. Currently recognized names are:
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>user</> <literal>user</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The database user name to connect as. Required; The database user name to connect as. Required;
there is no default. there is no default.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>database</> <literal>database</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The database to connect to. Defaults to the user name. The database to connect to. Defaults to the user name.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>options</> <literal>options</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Command-line arguments for the backend. (This is Command-line arguments for the backend. (This is
deprecated in favor of setting individual run-time deprecated in favor of setting individual run-time
parameters.) parameters.)
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
In addition to the above, any run-time parameter that can be In addition to the above, any run-time parameter that can be
set at backend start time may be listed. Such settings set at backend start time may be listed. Such settings
will be applied during backend start (after parsing the will be applied during backend start (after parsing the
command-line options if any). The values will act as command-line options if any). The values will act as
session defaults. session defaults.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
String String
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The parameter value. The parameter value.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Sync (F) Sync (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('S') Byte1('S')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a Sync command. Identifies the message as a Sync command.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Terminate (F) Terminate (F)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
Byte1('X') Byte1('X')
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Identifies the message as a termination. Identifies the message as a termination.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
Int32(4) Int32(4)
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Length of message contents in bytes, including self. Length of message contents in bytes, including self.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</sect1> </sect1>
<Sect1 id="protocol-error-fields"> <sect1 id="protocol-error-fields">
<Title>Error and Notice Message Fields</Title> <title>Error and Notice Message Fields</title>
<para> <para>
This section describes the fields that may appear in ErrorResponse and This section describes the fields that may appear in ErrorResponse and
...@@ -3868,165 +3868,165 @@ token. Note that any given field type should appear at most once per ...@@ -3868,165 +3868,165 @@ token. Note that any given field type should appear at most once per
message. message.
</para> </para>
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>S</> <literal>S</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Severity: the field contents are Severity: the field contents are
<literal>ERROR</>, <literal>FATAL</>, or <literal>ERROR</>, <literal>FATAL</>, or
<literal>PANIC</> (in an error message), or <literal>PANIC</> (in an error message), or
<literal>WARNING</>, <literal>NOTICE</>, <literal>DEBUG</>, <literal>WARNING</>, <literal>NOTICE</>, <literal>DEBUG</>,
<literal>INFO</>, or <literal>LOG</> (in a notice message), <literal>INFO</>, or <literal>LOG</> (in a notice message),
or a localized translation of one of these. Always present. or a localized translation of one of these. Always present.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>C</> <literal>C</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Code: the SQLSTATE code for the error (see <xref Code: the SQLSTATE code for the error (see <xref
linkend="errcodes-appendix">). Not localizable. Always present. linkend="errcodes-appendix">). Not localizable. Always present.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>M</> <literal>M</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Message: the primary human-readable error message. Message: the primary human-readable error message.
This should be accurate but terse (typically one line). This should be accurate but terse (typically one line).
Always present. Always present.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>D</> <literal>D</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Detail: an optional secondary error message carrying more Detail: an optional secondary error message carrying more
detail about the problem. May run to multiple lines. detail about the problem. May run to multiple lines.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>H</> <literal>H</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Hint: an optional suggestion what to do about the problem. Hint: an optional suggestion what to do about the problem.
This is intended to differ from Detail in that it offers advice This is intended to differ from Detail in that it offers advice
(potentially inappropriate) rather than hard facts. (potentially inappropriate) rather than hard facts.
May run to multiple lines. May run to multiple lines.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>P</> <literal>P</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Position: the field value is a decimal ASCII integer, indicating Position: the field value is a decimal ASCII integer, indicating
an error cursor position as an index into the original query string. an error cursor position as an index into the original query string.
The first character has index 1, and positions are measured in The first character has index 1, and positions are measured in
characters not bytes. characters not bytes.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>p</> <literal>p</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Internal position: this is defined the same as the <literal>P</> Internal position: this is defined the same as the <literal>P</>
field, but it is used when the cursor position refers to an internally field, but it is used when the cursor position refers to an internally
generated command rather than the one submitted by the client. generated command rather than the one submitted by the client.
The <literal>q</> field will always appear when this field appears. The <literal>q</> field will always appear when this field appears.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>q</> <literal>q</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Internal query: the text of a failed internally-generated command. Internal query: the text of a failed internally-generated command.
This could be, for example, a SQL query issued by a PL/pgSQL function. This could be, for example, a SQL query issued by a PL/pgSQL function.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>W</> <literal>W</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Where: an indication of the context in which the error occurred. Where: an indication of the context in which the error occurred.
Presently this includes a call stack traceback of active Presently this includes a call stack traceback of active
procedural language functions and internally-generated queries. procedural language functions and internally-generated queries.
The trace is one entry per line, most recent first. The trace is one entry per line, most recent first.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>F</> <literal>F</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
File: the file name of the source-code location where the error File: the file name of the source-code location where the error
was reported. was reported.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>L</> <literal>L</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Line: the line number of the source-code location where the error Line: the line number of the source-code location where the error
was reported. was reported.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
<literal>R</> <literal>R</>
</Term> </term>
<ListItem> <listitem>
<Para> <para>
Routine: the name of the source-code routine reporting the error. Routine: the name of the source-code routine reporting the error.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
<para> <para>
The client is responsible for formatting displayed information to meet its The client is responsible for formatting displayed information to meet its
...@@ -4038,8 +4038,8 @@ not line breaks. ...@@ -4038,8 +4038,8 @@ not line breaks.
</sect1> </sect1>
<Sect1 id="protocol-changes"> <sect1 id="protocol-changes">
<Title>Summary of Changes since Protocol 2.0</Title> <title>Summary of Changes since Protocol 2.0</title>
<para> <para>
This section provides a quick checklist of changes, for the benefit of This section provides a quick checklist of changes, for the benefit of
...@@ -4143,4 +4143,4 @@ string parameter; this has been removed. ...@@ -4143,4 +4143,4 @@ string parameter; this has been removed.
</sect1> </sect1>
</Chapter> </chapter>
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.49 2005/01/04 03:58:16 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.50 2005/01/23 00:30:31 momjian Exp $ -->
<refentry id="APP-PGRESTORE"> <refentry id="APP-PGRESTORE">
<refmeta> <refmeta>
...@@ -230,8 +230,8 @@ ...@@ -230,8 +230,8 @@
<term><option>--use-list=<replaceable class="parameter">list-file</replaceable></option></term> <term><option>--use-list=<replaceable class="parameter">list-file</replaceable></option></term>
<listitem> <listitem>
<para> <para>
Restore elements in <REPLACEABLE Restore elements in <replaceable class="PARAMETER">
CLASS="PARAMETER">list-file</REPLACEABLE> only, and in the list-file</replaceable> only, and in the
order they appear in the file. Lines can be moved and may also order they appear in the file. Lines can be moved and may also
be commented out by placing a <literal>;</literal> at the be commented out by placing a <literal>;</literal> at the
start of the line. (See below for examples.) start of the line. (See below for examples.)
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.323 2005/01/22 22:56:36 momjian Exp $ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.324 2005/01/23 00:30:18 momjian Exp $
--> -->
<appendix id="release"> <appendix id="release">
...@@ -9777,31 +9777,31 @@ New Ports ...@@ -9777,31 +9777,31 @@ New Ports
</para> </para>
<!-- <!--
Contributors (appologies to any missed) Contributors (appologies to any missed)
* Kurt J. Lidl <lidl@va.pubnix.com> * Kurt J. Lidl &lt;lidl@va.pubnix.com&gt;
(missed in first run, but no less important) (missed in first run, but no less important)
* Erich Stamberger <eberger@gewi.kfunigraz.ac.at> * Erich Stamberger &lt;eberger@gewi.kfunigraz.ac.at&gt;
* Jason Wright <jason@shiloh.vnet.net> * Jason Wright &lt;jason@shiloh.vnet.net&gt;
* Cees de Groot <C.deGroot@inter.NL.net> * Cees de Groot &lt;C.deGroot@inter.NL.net&gt;
* ernst.molitor@uni-bonn.de * ernst.molitor@uni-bonn.de
* michael.siebenborn@ae3.Hypo.DE (Michael Siebenborn (6929)) * michael.siebenborn@ae3.Hypo.DE (Michael Siebenborn (6929))
* Brian E. Gallew <geek+@cmu.edu> * Brian E. Gallew &lt;geek+@cmu.edu&gt;
* Vadim B. Mikheev <vadim@sable.krasnoyarsk.su> * Vadim B. Mikheev &lt;vadim@sable.krasnoyarsk.su&gt;
* Adam Sussman <myddryn@vidya.com> * Adam Sussman &lt;myddryn@vidya.com&gt;
* Chris Dunlop <chris@onthe.net.au> * Chris Dunlop &lt;chris@onthe.net.au&gt;
* Marc G. Fournier <scrappy@ki.net> * Marc G. Fournier &lt;scrappy@ki.net&gt;
* Dan McGuirk <mcguirk@indirect.com> * Dan McGuirk &lt;mcguirk@indirect.com&gt;
* Dr_George_D_Detlefsen <drgeorge@ilt.com> * Dr_George_D_Detlefsen &lt;drgeorge@ilt.com&gt;
* Erich Stamberger <eberger@gewi.kfunigraz.ac.at> * Erich Stamberger &lt;eberger@gewi.kfunigraz.ac.at&gt;
* Massimo Dal Zotto <dz@cs.unitn.it> * Massimo Dal Zotto &lt;dz@cs.unitn.it&gt;
* Randy Kunkee <kunkee@Starbase.NeoSoft.COM> * Randy Kunkee &lt;kunkee@Starbase.NeoSoft.COM&gt;
* Rick Weldon <rick@wisetech.com> * Rick Weldon &lt;rick@wisetech.com&gt;
* Thomas van Reimersdahl <reimersd@dali.techinfo.rwth-aachen.de> * Thomas van Reimersdahl &lt;reimersd@dali.techinfo.rwth-aachen.de&gt;
* david bennett <dave@bensoft.com> * david bennett &lt;dave@bensoft.com&gt;
* ernst.molitor@uni-bonn.de * ernst.molitor@uni-bonn.de
* Julian Assange <proff@suburbia.net> * Julian Assange &lt;proff@suburbia.net&gt;
* Bruce Momjian <pgman@candle.pha.pa.us> * Bruce Momjian &lt;pgman@candle.pha.pa.us&gt;
* Paul "Shag" Walmsley <ccshag@cclabs.missouri.edu> * Paul "Shag" Walmsley &lt;ccshag@cclabs.missouri.edu&gt;
* "Alistair G. Crooks" <azcb0@sde.uts.amdahl.com> * "Alistair G. Crooks" &lt;azcb0@sde.uts.amdahl.com&gt;
--> -->
</sect2> </sect2>
</sect1> </sect1>
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/rules.sgml,v 1.39 2005/01/22 22:56:36 momjian Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/rules.sgml,v 1.40 2005/01/23 00:30:18 momjian Exp $ -->
<Chapter Id="rules"> <chapter id="rules">
<Title>The Rule System</Title> <title>The Rule System</title>
<indexterm zone="rules"> <indexterm zone="rules">
<primary>rule</primary> <primary>rule</primary>
</indexterm> </indexterm>
<Para> <para>
This chapter discusses the rule system in This chapter discusses the rule system in
<productname>PostgreSQL</productname>. Production rule systems <productname>PostgreSQL</productname>. Production rule systems
are conceptually simple, but there are many subtle points are conceptually simple, but there are many subtle points
involved in actually using them. involved in actually using them.
</Para> </para>
<Para> <para>
Some other database systems define active database rules, which Some other database systems define active database rules, which
are usually stored procedures and triggers. In are usually stored procedures and triggers. In
<productname>PostgreSQL</productname>, these can be implemented <productname>PostgreSQL</productname>, these can be implemented
using functions and triggers as well. using functions and triggers as well.
</Para> </para>
<Para> <para>
The rule system (more precisely speaking, the query rewrite rule The rule system (more precisely speaking, the query rewrite rule
system) is totally different from stored procedures and triggers. system) is totally different from stored procedures and triggers.
It modifies queries to take rules into consideration, and then It modifies queries to take rules into consideration, and then
...@@ -33,31 +33,31 @@ ...@@ -33,31 +33,31 @@
linkend="ONG90">. linkend="ONG90">.
</para> </para>
<Sect1 id="querytree"> <sect1 id="querytree">
<Title>The Query Tree</Title> <title>The Query Tree</title>
<indexterm zone="querytree"> <indexterm zone="querytree">
<primary>query tree</primary> <primary>query tree</primary>
</indexterm> </indexterm>
<Para> <para>
To understand how the rule system works it is necessary to know To understand how the rule system works it is necessary to know
when it is invoked and what its input and results are. when it is invoked and what its input and results are.
</Para> </para>
<Para> <para>
The rule system is located between the parser and the planner. The rule system is located between the parser and the planner.
It takes the output of the parser, one query tree, and the user-defined It takes the output of the parser, one query tree, and the user-defined
rewrite rules, which are also rewrite rules, which are also
query trees with some extra information, and creates zero or more query trees with some extra information, and creates zero or more
query trees as result. So its input and output are always things query trees as result. So its input and output are always things
the parser itself could have produced and thus, anything it sees the parser itself could have produced and thus, anything it sees
is basically representable as an <Acronym>SQL</Acronym> statement. is basically representable as an <acronym>SQL</acronym> statement.
</Para> </para>
<Para> <para>
Now what is a query tree? It is an internal representation of an Now what is a query tree? It is an internal representation of an
<Acronym>SQL</Acronym> statement where the single parts that it is <acronym>SQL</acronym> statement where the single parts that it is
built from are stored separately. These query trees can be shown built from are stored separately. These query trees can be shown
in the server log if you set the configuration parameters in the server log if you set the configuration parameters
<varname>debug_print_parse</varname>, <varname>debug_print_parse</varname>,
...@@ -66,94 +66,94 @@ ...@@ -66,94 +66,94 @@
stored as query trees, in the system catalog stored as query trees, in the system catalog
<structname>pg_rewrite</structname>. They are not formatted like <structname>pg_rewrite</structname>. They are not formatted like
the log output, but they contain exactly the same information. the log output, but they contain exactly the same information.
</Para> </para>
<Para> <para>
Reading a raw query tree requires some experience. But since Reading a raw query tree requires some experience. But since
<Acronym>SQL</Acronym> representations of query trees are <acronym>SQL</acronym> representations of query trees are
sufficient to understand the rule system, this chapter will not sufficient to understand the rule system, this chapter will not
teach how to read them. teach how to read them.
</Para> </para>
<Para> <para>
When reading the <Acronym>SQL</Acronym> representations of the When reading the <acronym>SQL</acronym> representations of the
query trees in this chapter it is necessary to be able to identify query trees in this chapter it is necessary to be able to identify
the parts the statement is broken into when it is in the query tree the parts the statement is broken into when it is in the query tree
structure. The parts of a query tree are structure. The parts of a query tree are
<VariableList> <variablelist>
<VarListEntry> <varlistentry>
<Term> <term>
the command type the command type
</Term> </term>
<ListItem> <listitem>
<Para> <para>
This is a simple value telling which command This is a simple value telling which command
(<command>SELECT</command>, <command>INSERT</command>, (<command>SELECT</command>, <command>INSERT</command>,
<command>UPDATE</command>, <command>DELETE</command>) produced <command>UPDATE</command>, <command>DELETE</command>) produced
the query tree. the query tree.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
the range table the range table
</Term> </term>
<indexterm><primary>range table</></> <indexterm><primary>range table</></>
<ListItem> <listitem>
<Para> <para>
The range table is a list of relations that are used in the query. The range table is a list of relations that are used in the query.
In a <command>SELECT</command> statement these are the relations given after In a <command>SELECT</command> statement these are the relations given after
the <literal>FROM</literal> key word. the <literal>FROM</literal> key word.
</Para> </para>
<Para> <para>
Every range table entry identifies a table or view and tells Every range table entry identifies a table or view and tells
by which name it is called in the other parts of the query. by which name it is called in the other parts of the query.
In the query tree, the range table entries are referenced by In the query tree, the range table entries are referenced by
number rather than by name, so here it doesn't matter if there number rather than by name, so here it doesn't matter if there
are duplicate names as it would in an <Acronym>SQL</Acronym> are duplicate names as it would in an <acronym>SQL</acronym>
statement. This can happen after the range tables of rules statement. This can happen after the range tables of rules
have been merged in. The examples in this chapter will not have have been merged in. The examples in this chapter will not have
this situation. this situation.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
the result relation the result relation
</Term> </term>
<ListItem> <listitem>
<Para> <para>
This is an index into the range table that identifies the This is an index into the range table that identifies the
relation where the results of the query go. relation where the results of the query go.
</Para> </para>
<Para> <para>
<command>SELECT</command> queries normally don't have a result <command>SELECT</command> queries normally don't have a result
relation. The special case of a <command>SELECT INTO</command> is relation. The special case of a <command>SELECT INTO</command> is
mostly identical to a <command>CREATE TABLE</command> followed by a mostly identical to a <command>CREATE TABLE</command> followed by a
<literal>INSERT ... SELECT</literal> and is not discussed <literal>INSERT ... SELECT</literal> and is not discussed
separately here. separately here.
</Para> </para>
<Para> <para>
For <command>INSERT</command>, <command>UPDATE</command>, and For <command>INSERT</command>, <command>UPDATE</command>, and
<command>DELETE</command> commands, the result relation is the table <command>DELETE</command> commands, the result relation is the table
(or view!) where the changes are to take effect. (or view!) where the changes are to take effect.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
the target list the target list
</Term> </term>
<indexterm><primary>target list</></> <indexterm><primary>target list</></>
<ListItem> <listitem>
<Para> <para>
The target list is a list of expressions that define the The target list is a list of expressions that define the
result of the query. In the case of a result of the query. In the case of a
<command>SELECT</command>, these expressions are the ones that <command>SELECT</command>, these expressions are the ones that
...@@ -163,17 +163,17 @@ ...@@ -163,17 +163,17 @@
abbreviation for all the column names of a relation. It is abbreviation for all the column names of a relation. It is
expanded by the parser into the individual columns, so the expanded by the parser into the individual columns, so the
rule system never sees it.) rule system never sees it.)
</Para> </para>
<Para> <para>
<command>DELETE</command> commands don't need a target list <command>DELETE</command> commands don't need a target list
because they don't produce any result. In fact, the planner will because they don't produce any result. In fact, the planner will
add a special <acronym>CTID</> entry to the empty target list, but add a special <acronym>CTID</> entry to the empty target list, but
this is after the rule system and will be discussed later; for the this is after the rule system and will be discussed later; for the
rule system, the target list is empty. rule system, the target list is empty.
</Para> </para>
<Para> <para>
For <command>INSERT</command> commands, the target list describes For <command>INSERT</command> commands, the target list describes
the new rows that should go into the result relation. It consists of the the new rows that should go into the result relation. It consists of the
expressions in the <literal>VALUES</> clause or the ones from the expressions in the <literal>VALUES</> clause or the ones from the
...@@ -183,9 +183,9 @@ ...@@ -183,9 +183,9 @@
the original command but have defaults. Any remaining columns (with the original command but have defaults. Any remaining columns (with
neither a given value nor a default) will be filled in by the neither a given value nor a default) will be filled in by the
planner with a constant null expression. planner with a constant null expression.
</Para> </para>
<Para> <para>
For <command>UPDATE</command> commands, the target list For <command>UPDATE</command> commands, the target list
describes the new rows that should replace the old ones. In the describes the new rows that should replace the old ones. In the
rule system, it contains just the expressions from the <literal>SET rule system, it contains just the expressions from the <literal>SET
...@@ -193,40 +193,40 @@ ...@@ -193,40 +193,40 @@
missing columns by inserting expressions that copy the values from missing columns by inserting expressions that copy the values from
the old row into the new one. And it will add the special the old row into the new one. And it will add the special
<acronym>CTID</> entry just as for <command>DELETE</command>, too. <acronym>CTID</> entry just as for <command>DELETE</command>, too.
</Para> </para>
<Para> <para>
Every entry in the target list contains an expression that can Every entry in the target list contains an expression that can
be a constant value, a variable pointing to a column of one be a constant value, a variable pointing to a column of one
of the relations in the range table, a parameter, or an expression of the relations in the range table, a parameter, or an expression
tree made of function calls, constants, variables, operators, etc. tree made of function calls, constants, variables, operators, etc.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
the qualification the qualification
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The query's qualification is an expression much like one of The query's qualification is an expression much like one of
those contained in the target list entries. The result value of those contained in the target list entries. The result value of
this expression is a Boolean that tells whether the operation this expression is a Boolean that tells whether the operation
(<command>INSERT</command>, <command>UPDATE</command>, (<command>INSERT</command>, <command>UPDATE</command>,
<command>DELETE</command>, or <command>SELECT</command>) for the <command>DELETE</command>, or <command>SELECT</command>) for the
final result row should be executed or not. It corresponds to the <literal>WHERE</> clause final result row should be executed or not. It corresponds to the <literal>WHERE</> clause
of an <Acronym>SQL</Acronym> statement. of an <acronym>SQL</acronym> statement.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
the join tree the join tree
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The query's join tree shows the structure of the <literal>FROM</> clause. The query's join tree shows the structure of the <literal>FROM</> clause.
For a simple query like <literal>SELECT ... FROM a, b, c</literal>, the join tree is just For a simple query like <literal>SELECT ... FROM a, b, c</literal>, the join tree is just
a list of the <literal>FROM</> items, because we are allowed to join them in a list of the <literal>FROM</> items, because we are allowed to join them in
...@@ -239,31 +239,31 @@ ...@@ -239,31 +239,31 @@
the top-level <literal>WHERE</> expression as a qualification attached to the the top-level <literal>WHERE</> expression as a qualification attached to the
top-level join-tree item, too. So really the join tree represents top-level join-tree item, too. So really the join tree represents
both the <literal>FROM</> and <literal>WHERE</> clauses of a <command>SELECT</command>. both the <literal>FROM</> and <literal>WHERE</> clauses of a <command>SELECT</command>.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
<VarListEntry> <varlistentry>
<Term> <term>
the others the others
</Term> </term>
<ListItem> <listitem>
<Para> <para>
The other parts of the query tree like the <literal>ORDER BY</> The other parts of the query tree like the <literal>ORDER BY</>
clause aren't of interest here. The rule system clause aren't of interest here. The rule system
substitutes some entries there while applying rules, but that substitutes some entries there while applying rules, but that
doesn't have much to do with the fundamentals of the rule doesn't have much to do with the fundamentals of the rule
system. system.
</Para> </para>
</ListItem> </listitem>
</VarListEntry> </varlistentry>
</VariableList> </variablelist>
</para> </para>
</Sect1> </sect1>
<Sect1 id="rules-views"> <sect1 id="rules-views">
<Title>Views and the Rule System</Title> <title>Views and the Rule System</title>
<indexterm zone="rules-views"> <indexterm zone="rules-views">
<primary>rule</primary> <primary>rule</primary>
...@@ -275,57 +275,57 @@ ...@@ -275,57 +275,57 @@
<secondary>implementation through rules</> <secondary>implementation through rules</>
</indexterm> </indexterm>
<Para> <para>
Views in <ProductName>PostgreSQL</ProductName> are implemented Views in <productname>PostgreSQL</productname> are implemented
using the rule system. In fact, there is essentially no difference using the rule system. In fact, there is essentially no difference
between between
<ProgramListing> <programlisting>
CREATE VIEW myview AS SELECT * FROM mytab; CREATE VIEW myview AS SELECT * FROM mytab;
</ProgramListing> </programlisting>
compared against the two commands compared against the two commands
<ProgramListing> <programlisting>
CREATE TABLE myview (<Replaceable>same column list as mytab</Replaceable>); CREATE TABLE myview (<replaceable>same column list as mytab</replaceable>);
CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD
SELECT * FROM mytab; SELECT * FROM mytab;
</ProgramListing> </programlisting>
because this is exactly what the <command>CREATE VIEW</command> because this is exactly what the <command>CREATE VIEW</command>
command does internally. This has some side effects. One of them command does internally. This has some side effects. One of them
is that the information about a view in the is that the information about a view in the
<ProductName>PostgreSQL</ProductName> system catalogs is exactly <productname>PostgreSQL</productname> system catalogs is exactly
the same as it is for a table. So for the parser, there is the same as it is for a table. So for the parser, there is
absolutely no difference between a table and a view. They are the absolutely no difference between a table and a view. They are the
same thing: relations. same thing: relations.
</Para> </para>
<Sect2 id="rules-select"> <sect2 id="rules-select">
<Title>How <command>SELECT</command> Rules Work</Title> <title>How <command>SELECT</command> Rules Work</title>
<indexterm zone="rules-select"> <indexterm zone="rules-select">
<primary>rule</primary> <primary>rule</primary>
<secondary sortas="SELECT">for SELECT</secondary> <secondary sortas="SELECT">for SELECT</secondary>
</indexterm> </indexterm>
<Para> <para>
Rules <literal>ON SELECT</> are applied to all queries as the last step, even Rules <literal>ON SELECT</> are applied to all queries as the last step, even
if the command given is an <command>INSERT</command>, if the command given is an <command>INSERT</command>,
<command>UPDATE</command> or <command>DELETE</command>. And they <command>UPDATE</command> or <command>DELETE</command>. And they
have different semantics from rules on the other command types in that they modify the have different semantics from rules on the other command types in that they modify the
query tree in place instead of creating a new one. So query tree in place instead of creating a new one. So
<command>SELECT</command> rules are described first. <command>SELECT</command> rules are described first.
</Para> </para>
<Para> <para>
Currently, there can be only one action in an <literal>ON SELECT</> rule, and it must Currently, there can be only one action in an <literal>ON SELECT</> rule, and it must
be an unconditional <command>SELECT</> action that is <literal>INSTEAD</>. This restriction was be an unconditional <command>SELECT</> action that is <literal>INSTEAD</>. This restriction was
required to make rules safe enough to open them for ordinary users, and required to make rules safe enough to open them for ordinary users, and
it restricts <literal>ON SELECT</> rules to act like views. it restricts <literal>ON SELECT</> rules to act like views.
</Para> </para>
<Para> <para>
The examples for this chapter are two join views that do some The examples for this chapter are two join views that do some
calculations and some more views using them in turn. One of the calculations and some more views using them in turn. One of the
two first views is customized later by adding rules for two first views is customized later by adding rules for
...@@ -336,24 +336,24 @@ CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD ...@@ -336,24 +336,24 @@ CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD
this makes things harder to get into. But it's better to have one this makes things harder to get into. But it's better to have one
example that covers all the points discussed step by step rather example that covers all the points discussed step by step rather
than having many different ones that might mix up in mind. than having many different ones that might mix up in mind.
</Para> </para>
<Para> <para>
For the example, we need a little <literal>min</literal> function that For the example, we need a little <literal>min</literal> function that
returns the lower of 2 integer values. We create that as returns the lower of 2 integer values. We create that as
<ProgramListing> <programlisting>
CREATE FUNCTION min(integer, integer) RETURNS integer AS $$ CREATE FUNCTION min(integer, integer) RETURNS integer AS $$
SELECT CASE WHEN $1 &lt; $2 THEN $1 ELSE $2 END SELECT CASE WHEN $1 &lt; $2 THEN $1 ELSE $2 END
$$ LANGUAGE SQL STRICT; $$ LANGUAGE SQL STRICT;
</ProgramListing> </programlisting>
</Para> </para>
<Para> <para>
The real tables we need in the first two rule system descriptions The real tables we need in the first two rule system descriptions
are these: are these:
<ProgramListing> <programlisting>
CREATE TABLE shoe_data ( CREATE TABLE shoe_data (
shoename text, -- primary key shoename text, -- primary key
sh_avail integer, -- available number of pairs sh_avail integer, -- available number of pairs
...@@ -375,15 +375,15 @@ CREATE TABLE unit ( ...@@ -375,15 +375,15 @@ CREATE TABLE unit (
un_name text, -- primary key un_name text, -- primary key
un_fact real -- factor to transform to cm un_fact real -- factor to transform to cm
); );
</ProgramListing> </programlisting>
As you can see, they represent shoe-store data. As you can see, they represent shoe-store data.
</Para> </para>
<Para> <para>
The views are created as The views are created as
<ProgramListing> <programlisting>
CREATE VIEW shoe AS CREATE VIEW shoe AS
SELECT sh.shoename, SELECT sh.shoename,
sh.sh_avail, sh.sh_avail,
...@@ -416,7 +416,7 @@ CREATE VIEW shoe_ready AS ...@@ -416,7 +416,7 @@ CREATE VIEW shoe_ready AS
WHERE rsl.sl_color = rsh.slcolor WHERE rsl.sl_color = rsh.slcolor
AND rsl.sl_len_cm &gt;= rsh.slminlen_cm AND rsl.sl_len_cm &gt;= rsh.slminlen_cm
AND rsl.sl_len_cm &lt;= rsh.slmaxlen_cm; AND rsl.sl_len_cm &lt;= rsh.slmaxlen_cm;
</ProgramListing> </programlisting>
The <command>CREATE VIEW</command> command for the The <command>CREATE VIEW</command> command for the
<literal>shoelace</literal> view (which is the simplest one we <literal>shoelace</literal> view (which is the simplest one we
...@@ -430,23 +430,23 @@ CREATE VIEW shoe_ready AS ...@@ -430,23 +430,23 @@ CREATE VIEW shoe_ready AS
The action of our rule has a query qualification. The action of our rule has a query qualification.
The action of the rule is one query tree that is a copy of the The action of the rule is one query tree that is a copy of the
<command>SELECT</command> statement in the view creation command. <command>SELECT</command> statement in the view creation command.
</Para> </para>
<Note> <note>
<Para> <para>
The two extra range The two extra range
table entries for <literal>NEW</> and <literal>OLD</> (named <literal>*NEW*</> and <literal>*OLD*</> for table entries for <literal>NEW</> and <literal>OLD</> (named <literal>*NEW*</> and <literal>*OLD*</> for
historical reasons in the printed query tree) you can see in historical reasons in the printed query tree) you can see in
the <structname>pg_rewrite</structname> entry aren't of interest the <structname>pg_rewrite</structname> entry aren't of interest
for <command>SELECT</command> rules. for <command>SELECT</command> rules.
</Para> </para>
</Note> </note>
<Para> <para>
Now we populate <literal>unit</literal>, <literal>shoe_data</literal> Now we populate <literal>unit</literal>, <literal>shoe_data</literal>
and <literal>shoelace_data</literal> and run a simple query on a view: and <literal>shoelace_data</literal> and run a simple query on a view:
<ProgramListing> <programlisting>
INSERT INTO unit VALUES ('cm', 1.0); INSERT INTO unit VALUES ('cm', 1.0);
INSERT INTO unit VALUES ('m', 100.0); INSERT INTO unit VALUES ('m', 100.0);
INSERT INTO unit VALUES ('inch', 2.54); INSERT INTO unit VALUES ('inch', 2.54);
...@@ -478,7 +478,7 @@ SELECT * FROM shoelace; ...@@ -478,7 +478,7 @@ SELECT * FROM shoelace;
sl5 | 4 | brown | 1 | m | 100 sl5 | 4 | brown | 1 | m | 100
sl6 | 0 | brown | 0.9 | m | 90 sl6 | 0 | brown | 0.9 | m | 90
(8 rows) (8 rows)
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
...@@ -487,12 +487,12 @@ SELECT * FROM shoelace; ...@@ -487,12 +487,12 @@ SELECT * FROM shoelace;
rules. The <literal>SELECT * FROM shoelace</literal> was rules. The <literal>SELECT * FROM shoelace</literal> was
interpreted by the parser and produced the query tree interpreted by the parser and produced the query tree
<ProgramListing> <programlisting>
SELECT shoelace.sl_name, shoelace.sl_avail, SELECT shoelace.sl_name, shoelace.sl_avail,
shoelace.sl_color, shoelace.sl_len, shoelace.sl_color, shoelace.sl_len,
shoelace.sl_unit, shoelace.sl_len_cm shoelace.sl_unit, shoelace.sl_len_cm
FROM shoelace shoelace; FROM shoelace shoelace;
</ProgramListing> </programlisting>
and this is given to the rule system. The rule system walks through the and this is given to the rule system. The rule system walks through the
range table and checks if there are rules range table and checks if there are rules
...@@ -500,23 +500,23 @@ SELECT shoelace.sl_name, shoelace.sl_avail, ...@@ -500,23 +500,23 @@ SELECT shoelace.sl_name, shoelace.sl_avail,
<literal>shoelace</literal> (the only one up to now) it finds the <literal>shoelace</literal> (the only one up to now) it finds the
<literal>_RETURN</literal> rule with the query tree <literal>_RETURN</literal> rule with the query tree
<ProgramListing> <programlisting>
SELECT s.sl_name, s.sl_avail, SELECT s.sl_name, s.sl_avail,
s.sl_color, s.sl_len, s.sl_unit, s.sl_color, s.sl_len, s.sl_unit,
s.sl_len * u.un_fact AS sl_len_cm s.sl_len * u.un_fact AS sl_len_cm
FROM shoelace *OLD*, shoelace *NEW*, FROM shoelace *OLD*, shoelace *NEW*,
shoelace_data s, unit u shoelace_data s, unit u
WHERE s.sl_unit = u.un_name; WHERE s.sl_unit = u.un_name;
</ProgramListing> </programlisting>
</Para> </para>
<Para> <para>
To expand the view, the rewriter simply creates a subquery range-table To expand the view, the rewriter simply creates a subquery range-table
entry containing the rule's action query tree, and substitutes this entry containing the rule's action query tree, and substitutes this
range table entry for the original one that referenced the view. The range table entry for the original one that referenced the view. The
resulting rewritten query tree is almost the same as if you had typed resulting rewritten query tree is almost the same as if you had typed
<ProgramListing> <programlisting>
SELECT shoelace.sl_name, shoelace.sl_avail, SELECT shoelace.sl_name, shoelace.sl_avail,
shoelace.sl_color, shoelace.sl_len, shoelace.sl_color, shoelace.sl_len,
shoelace.sl_unit, shoelace.sl_len_cm shoelace.sl_unit, shoelace.sl_len_cm
...@@ -528,7 +528,7 @@ SELECT shoelace.sl_name, shoelace.sl_avail, ...@@ -528,7 +528,7 @@ SELECT shoelace.sl_name, shoelace.sl_avail,
s.sl_len * u.un_fact AS sl_len_cm s.sl_len * u.un_fact AS sl_len_cm
FROM shoelace_data s, unit u FROM shoelace_data s, unit u
WHERE s.sl_unit = u.un_name) shoelace; WHERE s.sl_unit = u.un_name) shoelace;
</ProgramListing> </programlisting>
There is one difference however: the subquery's range table has two There is one difference however: the subquery's range table has two
extra entries <literal>shoelace *OLD*</> and <literal>shoelace *NEW*</>. These entries don't extra entries <literal>shoelace *OLD*</> and <literal>shoelace *NEW*</>. These entries don't
...@@ -539,9 +539,9 @@ SELECT shoelace.sl_name, shoelace.sl_avail, ...@@ -539,9 +539,9 @@ SELECT shoelace.sl_name, shoelace.sl_avail,
executor will still check that the user has proper privileges to access executor will still check that the user has proper privileges to access
the view, even though there's no direct use of the view in the rewritten the view, even though there's no direct use of the view in the rewritten
query. query.
</Para> </para>
<Para> <para>
That was the first rule applied. The rule system will continue checking That was the first rule applied. The rule system will continue checking
the remaining range-table entries in the top query (in this example there the remaining range-table entries in the top query (in this example there
are no more), and it will recursively check the range-table entries in are no more), and it will recursively check the range-table entries in
...@@ -550,14 +550,14 @@ SELECT shoelace.sl_name, shoelace.sl_avail, ...@@ -550,14 +550,14 @@ SELECT shoelace.sl_name, shoelace.sl_avail,
In this example, there are no rewrite rules for <literal>shoelace_data</> or <literal>unit</>, In this example, there are no rewrite rules for <literal>shoelace_data</> or <literal>unit</>,
so rewriting is complete and the above is the final result given to so rewriting is complete and the above is the final result given to
the planner. the planner.
</Para> </para>
<Para> <para>
No we want to write a query that finds out for which shoes currently in the store No we want to write a query that finds out for which shoes currently in the store
we have the matching shoelaces (color and length) and where the we have the matching shoelaces (color and length) and where the
total number of exactly matching pairs is greater or equal to two. total number of exactly matching pairs is greater or equal to two.
<ProgramListing> <programlisting>
SELECT * FROM shoe_ready WHERE total_avail &gt;= 2; SELECT * FROM shoe_ready WHERE total_avail &gt;= 2;
shoename | sh_avail | sl_name | sl_avail | total_avail shoename | sh_avail | sl_name | sl_avail | total_avail
...@@ -565,25 +565,25 @@ SELECT * FROM shoe_ready WHERE total_avail &gt;= 2; ...@@ -565,25 +565,25 @@ SELECT * FROM shoe_ready WHERE total_avail &gt;= 2;
sh1 | 2 | sl1 | 5 | 2 sh1 | 2 | sl1 | 5 | 2
sh3 | 4 | sl7 | 7 | 4 sh3 | 4 | sl7 | 7 | 4
(2 rows) (2 rows)
</ProgramListing> </programlisting>
</Para> </para>
<Para> <para>
The output of the parser this time is the query tree The output of the parser this time is the query tree
<ProgramListing> <programlisting>
SELECT shoe_ready.shoename, shoe_ready.sh_avail, SELECT shoe_ready.shoename, shoe_ready.sh_avail,
shoe_ready.sl_name, shoe_ready.sl_avail, shoe_ready.sl_name, shoe_ready.sl_avail,
shoe_ready.total_avail shoe_ready.total_avail
FROM shoe_ready shoe_ready FROM shoe_ready shoe_ready
WHERE shoe_ready.total_avail &gt;= 2; WHERE shoe_ready.total_avail &gt;= 2;
</ProgramListing> </programlisting>
The first rule applied will be the one for the The first rule applied will be the one for the
<literal>shoe_ready</literal> view and it results in the <literal>shoe_ready</literal> view and it results in the
query tree query tree
<ProgramListing> <programlisting>
SELECT shoe_ready.shoename, shoe_ready.sh_avail, SELECT shoe_ready.shoename, shoe_ready.sh_avail,
shoe_ready.sl_name, shoe_ready.sl_avail, shoe_ready.sl_name, shoe_ready.sl_avail,
shoe_ready.total_avail shoe_ready.total_avail
...@@ -597,13 +597,13 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail, ...@@ -597,13 +597,13 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail,
AND rsl.sl_len_cm &gt;= rsh.slminlen_cm AND rsl.sl_len_cm &gt;= rsh.slminlen_cm
AND rsl.sl_len_cm &lt;= rsh.slmaxlen_cm) shoe_ready AND rsl.sl_len_cm &lt;= rsh.slmaxlen_cm) shoe_ready
WHERE shoe_ready.total_avail &gt;= 2; WHERE shoe_ready.total_avail &gt;= 2;
</ProgramListing> </programlisting>
Similarly, the rules for <literal>shoe</literal> and Similarly, the rules for <literal>shoe</literal> and
<literal>shoelace</literal> are substituted into the range table of <literal>shoelace</literal> are substituted into the range table of
the subquery, leading to a three-level final query tree: the subquery, leading to a three-level final query tree:
<ProgramListing> <programlisting>
SELECT shoe_ready.shoename, shoe_ready.sh_avail, SELECT shoe_ready.shoename, shoe_ready.sh_avail,
shoe_ready.sl_name, shoe_ready.sl_avail, shoe_ready.sl_name, shoe_ready.sl_avail,
shoe_ready.total_avail shoe_ready.total_avail
...@@ -634,7 +634,7 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail, ...@@ -634,7 +634,7 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail,
AND rsl.sl_len_cm &gt;= rsh.slminlen_cm AND rsl.sl_len_cm &gt;= rsh.slminlen_cm
AND rsl.sl_len_cm &lt;= rsh.slmaxlen_cm) shoe_ready AND rsl.sl_len_cm &lt;= rsh.slmaxlen_cm) shoe_ready
WHERE shoe_ready.total_avail &gt; 2; WHERE shoe_ready.total_avail &gt; 2;
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
...@@ -650,8 +650,8 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail, ...@@ -650,8 +650,8 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail,
system doesn't have to concern itself with. system doesn't have to concern itself with.
</para> </para>
<Note> <note>
<Para> <para>
There is currently no recursion stopping mechanism for view rules There is currently no recursion stopping mechanism for view rules
in the rule system (only for the other kinds of rules). This in the rule system (only for the other kinds of rules). This
doesn't hurt much, because the only way to push this into an doesn't hurt much, because the only way to push this into an
...@@ -662,20 +662,20 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail, ...@@ -662,20 +662,20 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail,
never happen if <command>CREATE VIEW</command> is used because for never happen if <command>CREATE VIEW</command> is used because for
the first <command>CREATE VIEW</command>, the second relation does the first <command>CREATE VIEW</command>, the second relation does
not exist and thus the first view cannot select from the second. not exist and thus the first view cannot select from the second.
</Para> </para>
</Note> </note>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>View Rules in Non-<command>SELECT</command> Statements</Title> <title>View Rules in Non-<command>SELECT</command> Statements</title>
<Para> <para>
Two details of the query tree aren't touched in the description of Two details of the query tree aren't touched in the description of
view rules above. These are the command type and the result relation. view rules above. These are the command type and the result relation.
In fact, view rules don't need this information. In fact, view rules don't need this information.
</Para> </para>
<Para> <para>
There are only a few differences between a query tree for a There are only a few differences between a query tree for a
<command>SELECT</command> and one for any other <command>SELECT</command> and one for any other
command. Obviously, they have a different command type and for a command. Obviously, they have a different command type and for a
...@@ -685,41 +685,41 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail, ...@@ -685,41 +685,41 @@ SELECT shoe_ready.shoename, shoe_ready.sh_avail,
<literal>t1</> and <literal>t2</> with columns <literal>a</> and <literal>t1</> and <literal>t2</> with columns <literal>a</> and
<literal>b</>, the query trees for the two statements <literal>b</>, the query trees for the two statements
<ProgramListing> <programlisting>
SELECT t2.b FROM t1, t2 WHERE t1.a = t2.a; SELECT t2.b FROM t1, t2 WHERE t1.a = t2.a;
UPDATE t1 SET b = t2.b WHERE t1.a = t2.a; UPDATE t1 SET b = t2.b WHERE t1.a = t2.a;
</ProgramListing> </programlisting>
are nearly identical. In particular: are nearly identical. In particular:
<ItemizedList> <itemizedlist>
<ListItem> <listitem>
<Para> <para>
The range tables contain entries for the tables <literal>t1</> and <literal>t2</>. The range tables contain entries for the tables <literal>t1</> and <literal>t2</>.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
The target lists contain one variable that points to column The target lists contain one variable that points to column
<literal>b</> of the range table entry for table <literal>t2</>. <literal>b</> of the range table entry for table <literal>t2</>.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
The qualification expressions compare the columns <literal>a</> of both The qualification expressions compare the columns <literal>a</> of both
range-table entries for equality. range-table entries for equality.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
The join trees show a simple join between <literal>t1</> and <literal>t2</>. The join trees show a simple join between <literal>t1</> and <literal>t2</>.
</Para> </para>
</ListItem> </listitem>
</ItemizedList> </itemizedlist>
</para> </para>
<para> <para>
...@@ -729,16 +729,16 @@ UPDATE t1 SET b = t2.b WHERE t1.a = t2.a; ...@@ -729,16 +729,16 @@ UPDATE t1 SET b = t2.b WHERE t1.a = t2.a;
the target list by the planner and the final query tree will read the target list by the planner and the final query tree will read
as as
<ProgramListing> <programlisting>
UPDATE t1 SET a = t1.a, b = t2.b WHERE t1.a = t2.a; UPDATE t1 SET a = t1.a, b = t2.b WHERE t1.a = t2.a;
</ProgramListing> </programlisting>
and thus the executor run over the join will produce exactly the and thus the executor run over the join will produce exactly the
same result set as a same result set as a
<ProgramListing> <programlisting>
SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a = t2.a; SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a = t2.a;
</ProgramListing> </programlisting>
will do. But there is a little problem in will do. But there is a little problem in
<command>UPDATE</command>: The executor does not care what the <command>UPDATE</command>: The executor does not care what the
...@@ -750,9 +750,9 @@ SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a = t2.a; ...@@ -750,9 +750,9 @@ SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a = t2.a;
this is an <command>UPDATE</command>, and it knows that this this is an <command>UPDATE</command>, and it knows that this
result should go into table <literal>t1</>. But which of the rows that are result should go into table <literal>t1</>. But which of the rows that are
there has to be replaced by the new row? there has to be replaced by the new row?
</Para> </para>
<Para> <para>
To resolve this problem, another entry is added to the target list To resolve this problem, another entry is added to the target list
in <command>UPDATE</command> (and also in in <command>UPDATE</command> (and also in
<command>DELETE</command>) statements: the current tuple ID <command>DELETE</command>) statements: the current tuple ID
...@@ -762,11 +762,11 @@ SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a = t2.a; ...@@ -762,11 +762,11 @@ SELECT t1.a, t2.b FROM t1, t2 WHERE t1.a = t2.a;
original row of <literal>t1</> to be updated. After adding the <acronym>CTID</> original row of <literal>t1</> to be updated. After adding the <acronym>CTID</>
to the target list, the query actually looks like to the target list, the query actually looks like
<ProgramListing> <programlisting>
SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a; SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a;
</ProgramListing> </programlisting>
Now another detail of <ProductName>PostgreSQL</ProductName> enters Now another detail of <productname>PostgreSQL</productname> enters
the stage. Old table rows aren't overwritten, and this the stage. Old table rows aren't overwritten, and this
is why <command>ROLLBACK</command> is fast. In an <command>UPDATE</command>, is why <command>ROLLBACK</command> is fast. In an <command>UPDATE</command>,
the new result row is inserted into the table (after stripping the the new result row is inserted into the table (after stripping the
...@@ -776,26 +776,26 @@ SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a; ...@@ -776,26 +776,26 @@ SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a;
and current transaction ID. Thus the old row is hidden, and after and current transaction ID. Thus the old row is hidden, and after
the transaction committed the vacuum cleaner can really move it the transaction committed the vacuum cleaner can really move it
out. out.
</Para> </para>
<Para> <para>
Knowing all that, we can simply apply view rules in absolutely Knowing all that, we can simply apply view rules in absolutely
the same way to any command. There is no difference. the same way to any command. There is no difference.
</Para> </para>
</Sect2> </sect2>
<Sect2> <sect2>
<Title>The Power of Views in <ProductName>PostgreSQL</ProductName></Title> <title>The Power of Views in <productname>PostgreSQL</productname></title>
<Para> <para>
The above demonstrates how the rule system incorporates view The above demonstrates how the rule system incorporates view
definitions into the original query tree. In the second example, a definitions into the original query tree. In the second example, a
simple <command>SELECT</command> from one view created a final simple <command>SELECT</command> from one view created a final
query tree that is a join of 4 tables (<literal>unit</> was used twice with query tree that is a join of 4 tables (<literal>unit</> was used twice with
different names). different names).
</Para> </para>
<Para> <para>
The benefit of implementing views with the rule system is, The benefit of implementing views with the rule system is,
that the planner has all that the planner has all
the information about which tables have to be scanned plus the the information about which tables have to be scanned plus the
...@@ -807,16 +807,16 @@ SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a; ...@@ -807,16 +807,16 @@ SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a;
The planner has to decide which is The planner has to decide which is
the best path to execute the query, and the more information the best path to execute the query, and the more information
the planner has, the better this decision can be. And the planner has, the better this decision can be. And
the rule system as implemented in <ProductName>PostgreSQL</ProductName> the rule system as implemented in <productname>PostgreSQL</productname>
ensures, that this is all information available about the query ensures, that this is all information available about the query
up to that point. up to that point.
</Para> </para>
</Sect2> </sect2>
<Sect2 id="rules-views-update"> <sect2 id="rules-views-update">
<Title>Updating a View</Title> <title>Updating a View</title>
<Para> <para>
What happens if a view is named as the target relation for an What happens if a view is named as the target relation for an
<command>INSERT</command>, <command>UPDATE</command>, or <command>INSERT</command>, <command>UPDATE</command>, or
<command>DELETE</command>? After doing the substitutions <command>DELETE</command>? After doing the substitutions
...@@ -824,18 +824,18 @@ SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a; ...@@ -824,18 +824,18 @@ SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a;
relation points at a subquery range-table entry. This will not relation points at a subquery range-table entry. This will not
work, so the rewriter throws an error if it sees it has produced work, so the rewriter throws an error if it sees it has produced
such a thing. such a thing.
</Para> </para>
<Para> <para>
To change this, we can define rules that modify the behavior of To change this, we can define rules that modify the behavior of
these kinds of commands. This is the topic of the next section. these kinds of commands. This is the topic of the next section.
</Para> </para>
</Sect2> </sect2>
</Sect1> </sect1>
<Sect1 id="rules-update"> <sect1 id="rules-update">
<Title>Rules on <command>INSERT</>, <command>UPDATE</>, and <command>DELETE</></Title> <title>Rules on <command>INSERT</>, <command>UPDATE</>, and <command>DELETE</></title>
<indexterm zone="rules-update"> <indexterm zone="rules-update">
<primary>rule</primary> <primary>rule</primary>
...@@ -852,67 +852,67 @@ SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a; ...@@ -852,67 +852,67 @@ SELECT t1.a, t2.b, t1.ctid FROM t1, t2 WHERE t1.a = t2.a;
<secondary sortas="DELETE">for DELETE</secondary> <secondary sortas="DELETE">for DELETE</secondary>
</indexterm> </indexterm>
<Para> <para>
Rules that are defined on <command>INSERT</>, <command>UPDATE</>, Rules that are defined on <command>INSERT</>, <command>UPDATE</>,
and <command>DELETE</> are significantly different from the view rules and <command>DELETE</> are significantly different from the view rules
described in the previous section. First, their <command>CREATE described in the previous section. First, their <command>CREATE
RULE</command> command allows more: RULE</command> command allows more:
<ItemizedList> <itemizedlist>
<ListItem> <listitem>
<Para> <para>
They are allowed to have no action. They are allowed to have no action.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
They can have multiple actions. They can have multiple actions.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
They can be <literal>INSTEAD</> or <literal>ALSO</> (default). They can be <literal>INSTEAD</> or <literal>ALSO</> (default).
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
The pseudorelations <literal>NEW</> and <literal>OLD</> become useful. The pseudorelations <literal>NEW</> and <literal>OLD</> become useful.
</Para> </para>
</ListItem> </listitem>
<ListItem> <listitem>
<Para> <para>
They can have rule qualifications. They can have rule qualifications.
</Para> </para>
</ListItem> </listitem>
</ItemizedList> </itemizedlist>
Second, they don't modify the query tree in place. Instead they Second, they don't modify the query tree in place. Instead they
create zero or more new query trees and can throw away the create zero or more new query trees and can throw away the
original one. original one.
</Para> </para>
<Sect2> <sect2>
<Title>How Update Rules Work</Title> <title>How Update Rules Work</title>
<Para> <para>
Keep the syntax Keep the syntax
<ProgramListing> <programlisting>
CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</> CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</>
TO <replaceable>object</> [WHERE <replaceable>rule_qualification</>] TO <replaceable>object</> [WHERE <replaceable>rule_qualification</>]
DO [ALSO|INSTEAD] [<replaceable>action</> | (<replaceable>actions</>) | NOTHING]; DO [ALSO|INSTEAD] [<replaceable>action</> | (<replaceable>actions</>) | NOTHING];
</ProgramListing> </programlisting>
in mind. in mind.
In the following, <firstterm>update rules</> means rules that are defined In the following, <firstterm>update rules</> means rules that are defined
on <command>INSERT</>, <command>UPDATE</>, or <command>DELETE</>. on <command>INSERT</>, <command>UPDATE</>, or <command>DELETE</>.
</Para> </para>
<Para> <para>
Update rules get applied by the rule system when the result Update rules get applied by the rule system when the result
relation and the command type of a query tree are equal to the relation and the command type of a query tree are equal to the
object and event given in the <command>CREATE RULE</command> command. object and event given in the <command>CREATE RULE</command> command.
...@@ -921,15 +921,15 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</> ...@@ -921,15 +921,15 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</>
There can be zero (<literal>NOTHING</> key word), one, or multiple actions. There can be zero (<literal>NOTHING</> key word), one, or multiple actions.
To simplify, we will look at a rule with one action. This rule To simplify, we will look at a rule with one action. This rule
can have a qualification or not and it can be <literal>INSTEAD</> or <literal>ALSO</> (default). can have a qualification or not and it can be <literal>INSTEAD</> or <literal>ALSO</> (default).
</Para> </para>
<Para> <para>
What is a rule qualification? It is a restriction that tells What is a rule qualification? It is a restriction that tells
when the actions of the rule should be done and when not. This when the actions of the rule should be done and when not. This
qualification can only reference the pseudorelations <literal>NEW</> and/or <literal>OLD</>, qualification can only reference the pseudorelations <literal>NEW</> and/or <literal>OLD</>,
which basically represent the relation that was given as object (but with a which basically represent the relation that was given as object (but with a
special meaning). special meaning).
</Para> </para>
<para> <para>
So we have four cases that produce the following query trees for So we have four cases that produce the following query trees for
...@@ -984,9 +984,9 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</> ...@@ -984,9 +984,9 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</>
added to the list. Since only qualified <literal>INSTEAD</> rules already add the added to the list. Since only qualified <literal>INSTEAD</> rules already add the
original query tree, we end up with either one or two output query trees original query tree, we end up with either one or two output query trees
for a rule with one action. for a rule with one action.
</Para> </para>
<Para> <para>
For <literal>ON INSERT</> rules, the original query (if not suppressed by <literal>INSTEAD</>) For <literal>ON INSERT</> rules, the original query (if not suppressed by <literal>INSTEAD</>)
is done before any actions added by rules. This allows the actions to is done before any actions added by rules. This allows the actions to
see the inserted row(s). But for <literal>ON UPDATE</> and <literal>ON see the inserted row(s). But for <literal>ON UPDATE</> and <literal>ON
...@@ -994,9 +994,9 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</> ...@@ -994,9 +994,9 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</>
This ensures that the actions can see the to-be-updated or to-be-deleted This ensures that the actions can see the to-be-updated or to-be-deleted
rows; otherwise, the actions might do nothing because they find no rows rows; otherwise, the actions might do nothing because they find no rows
matching their qualifications. matching their qualifications.
</Para> </para>
<Para> <para>
The query trees generated from rule actions are thrown into the The query trees generated from rule actions are thrown into the
rewrite system again, and maybe more rules get applied resulting rewrite system again, and maybe more rules get applied resulting
in more or less query trees. in more or less query trees.
...@@ -1006,9 +1006,9 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</> ...@@ -1006,9 +1006,9 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</>
If after 100 iterations there are still update rules to apply, the If after 100 iterations there are still update rules to apply, the
rule system assumes a loop over multiple rule definitions and reports rule system assumes a loop over multiple rule definitions and reports
an error. an error.
</Para> </para>
<Para> <para>
The query trees found in the actions of the The query trees found in the actions of the
<structname>pg_rewrite</structname> system catalog are only <structname>pg_rewrite</structname> system catalog are only
templates. Since they can reference the range-table entries for templates. Since they can reference the range-table entries for
...@@ -1020,25 +1020,25 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</> ...@@ -1020,25 +1020,25 @@ CREATE RULE <replaceable>rule_name</> AS ON <replaceable>event</>
a null value (for an <command>INSERT</command>). Any reference to <literal>OLD</> is a null value (for an <command>INSERT</command>). Any reference to <literal>OLD</> is
replaced by a reference to the range-table entry that is the replaced by a reference to the range-table entry that is the
result relation. result relation.
</Para> </para>
<Para> <para>
After the system is done applying update rules, it applies view rules to the After the system is done applying update rules, it applies view rules to the
produced query tree(s). Views cannot insert new update actions so produced query tree(s). Views cannot insert new update actions so
there is no need to apply update rules to the output of view rewriting. there is no need to apply update rules to the output of view rewriting.
</Para> </para>
<Sect3> <sect3>
<Title>A First Rule Step by Step</Title> <title>A First Rule Step by Step</title>
<Para> <para>
Say we want to trace changes to the <literal>sl_avail</> column in the Say we want to trace changes to the <literal>sl_avail</> column in the
<literal>shoelace_data</literal> relation. So we set up a log table <literal>shoelace_data</literal> relation. So we set up a log table
and a rule that conditionally writes a log entry when an and a rule that conditionally writes a log entry when an
<command>UPDATE</command> is performed on <command>UPDATE</command> is performed on
<literal>shoelace_data</literal>. <literal>shoelace_data</literal>.
<ProgramListing> <programlisting>
CREATE TABLE shoelace_log ( CREATE TABLE shoelace_log (
sl_name text, -- shoelace changed sl_name text, -- shoelace changed
sl_avail integer, -- new available value sl_avail integer, -- new available value
...@@ -1054,53 +1054,53 @@ CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data ...@@ -1054,53 +1054,53 @@ CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data
current_user, current_user,
current_timestamp current_timestamp
); );
</ProgramListing> </programlisting>
</Para> </para>
<Para> <para>
Now someone does: Now someone does:
<ProgramListing> <programlisting>
UPDATE shoelace_data SET sl_avail = 6 WHERE sl_name = 'sl7'; UPDATE shoelace_data SET sl_avail = 6 WHERE sl_name = 'sl7';
</ProgramListing> </programlisting>
and we look at the log table: and we look at the log table:
<ProgramListing> <programlisting>
SELECT * FROM shoelace_log; SELECT * FROM shoelace_log;
sl_name | sl_avail | log_who | log_when sl_name | sl_avail | log_who | log_when
---------+----------+---------+---------------------------------- ---------+----------+---------+----------------------------------
sl7 | 6 | Al | Tue Oct 20 16:14:45 1998 MET DST sl7 | 6 | Al | Tue Oct 20 16:14:45 1998 MET DST
(1 row) (1 row)
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
That's what we expected. What happened in the background is the following. That's what we expected. What happened in the background is the following.
The parser created the query tree The parser created the query tree
<ProgramListing> <programlisting>
UPDATE shoelace_data SET sl_avail = 6 UPDATE shoelace_data SET sl_avail = 6
FROM shoelace_data shoelace_data FROM shoelace_data shoelace_data
WHERE shoelace_data.sl_name = 'sl7'; WHERE shoelace_data.sl_name = 'sl7';
</ProgramListing> </programlisting>
There is a rule <literal>log_shoelace</literal> that is <literal>ON UPDATE</> with the rule There is a rule <literal>log_shoelace</literal> that is <literal>ON UPDATE</> with the rule
qualification expression qualification expression
<ProgramListing> <programlisting>
NEW.sl_avail &lt;&gt; OLD.sl_avail NEW.sl_avail &lt;&gt; OLD.sl_avail
</ProgramListing> </programlisting>
and the action and the action
<ProgramListing> <programlisting>
INSERT INTO shoelace_log VALUES ( INSERT INTO shoelace_log VALUES (
*NEW*.sl_name, *NEW*.sl_avail, *NEW*.sl_name, *NEW*.sl_avail,
current_user, current_timestamp ) current_user, current_timestamp )
FROM shoelace_data *NEW*, shoelace_data *OLD*; FROM shoelace_data *NEW*, shoelace_data *OLD*;
</ProgramListing> </programlisting>
(This looks a little strange since you can't normally write (This looks a little strange since you can't normally write
<literal>INSERT ... VALUES ... FROM</>. The <literal>FROM</> <literal>INSERT ... VALUES ... FROM</>. The <literal>FROM</>
...@@ -1108,33 +1108,33 @@ INSERT INTO shoelace_log VALUES ( ...@@ -1108,33 +1108,33 @@ INSERT INTO shoelace_log VALUES (
in the query tree for <literal>*NEW*</> and <literal>*OLD*</>. in the query tree for <literal>*NEW*</> and <literal>*OLD*</>.
These are needed so that they can be referenced by variables in These are needed so that they can be referenced by variables in
the <command>INSERT</command> command's query tree.) the <command>INSERT</command> command's query tree.)
</Para> </para>
<Para> <para>
The rule is a qualified <literal>ALSO</> rule, so the rule system The rule is a qualified <literal>ALSO</> rule, so the rule system
has to return two query trees: the modified rule action and the original has to return two query trees: the modified rule action and the original
query tree. In step 1, the range table of the original query is query tree. In step 1, the range table of the original query is
incorporated into the rule's action query tree. This results in: incorporated into the rule's action query tree. This results in:
<ProgramListing> <programlisting>
INSERT INTO shoelace_log VALUES ( INSERT INTO shoelace_log VALUES (
*NEW*.sl_name, *NEW*.sl_avail, *NEW*.sl_name, *NEW*.sl_avail,
current_user, current_timestamp ) current_user, current_timestamp )
FROM shoelace_data *NEW*, shoelace_data *OLD*, FROM shoelace_data *NEW*, shoelace_data *OLD*,
<emphasis>shoelace_data shoelace_data</emphasis>; <emphasis>shoelace_data shoelace_data</emphasis>;
</ProgramListing> </programlisting>
In step 2, the rule qualification is added to it, so the result set In step 2, the rule qualification is added to it, so the result set
is restricted to rows where <literal>sl_avail</> changes: is restricted to rows where <literal>sl_avail</> changes:
<ProgramListing> <programlisting>
INSERT INTO shoelace_log VALUES ( INSERT INTO shoelace_log VALUES (
*NEW*.sl_name, *NEW*.sl_avail, *NEW*.sl_name, *NEW*.sl_avail,
current_user, current_timestamp ) current_user, current_timestamp )
FROM shoelace_data *NEW*, shoelace_data *OLD*, FROM shoelace_data *NEW*, shoelace_data *OLD*,
shoelace_data shoelace_data shoelace_data shoelace_data
<emphasis>WHERE *NEW*.sl_avail &lt;&gt; *OLD*.sl_avail</emphasis>; <emphasis>WHERE *NEW*.sl_avail &lt;&gt; *OLD*.sl_avail</emphasis>;
</ProgramListing> </programlisting>
(This looks even stranger, since <literal>INSERT ... VALUES</> doesn't have (This looks even stranger, since <literal>INSERT ... VALUES</> doesn't have
a <literal>WHERE</> clause either, but the planner and executor will have no a <literal>WHERE</> clause either, but the planner and executor will have no
...@@ -1147,7 +1147,7 @@ INSERT INTO shoelace_log VALUES ( ...@@ -1147,7 +1147,7 @@ INSERT INTO shoelace_log VALUES (
restricting the result set further to only the rows that would have been touched restricting the result set further to only the rows that would have been touched
by the original query: by the original query:
<ProgramListing> <programlisting>
INSERT INTO shoelace_log VALUES ( INSERT INTO shoelace_log VALUES (
*NEW*.sl_name, *NEW*.sl_avail, *NEW*.sl_name, *NEW*.sl_avail,
current_user, current_timestamp ) current_user, current_timestamp )
...@@ -1155,7 +1155,7 @@ INSERT INTO shoelace_log VALUES ( ...@@ -1155,7 +1155,7 @@ INSERT INTO shoelace_log VALUES (
shoelace_data shoelace_data shoelace_data shoelace_data
WHERE *NEW*.sl_avail &lt;&gt; *OLD*.sl_avail WHERE *NEW*.sl_avail &lt;&gt; *OLD*.sl_avail
<emphasis>AND shoelace_data.sl_name = 'sl7'</emphasis>; <emphasis>AND shoelace_data.sl_name = 'sl7'</emphasis>;
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
...@@ -1163,7 +1163,7 @@ INSERT INTO shoelace_log VALUES ( ...@@ -1163,7 +1163,7 @@ INSERT INTO shoelace_log VALUES (
original query tree or by the matching variable references original query tree or by the matching variable references
from the result relation: from the result relation:
<ProgramListing> <programlisting>
INSERT INTO shoelace_log VALUES ( INSERT INTO shoelace_log VALUES (
<emphasis>shoelace_data.sl_name</emphasis>, <emphasis>6</emphasis>, <emphasis>shoelace_data.sl_name</emphasis>, <emphasis>6</emphasis>,
current_user, current_timestamp ) current_user, current_timestamp )
...@@ -1171,14 +1171,14 @@ INSERT INTO shoelace_log VALUES ( ...@@ -1171,14 +1171,14 @@ INSERT INTO shoelace_log VALUES (
shoelace_data shoelace_data shoelace_data shoelace_data
WHERE <emphasis>6</emphasis> &lt;&gt; *OLD*.sl_avail WHERE <emphasis>6</emphasis> &lt;&gt; *OLD*.sl_avail
AND shoelace_data.sl_name = 'sl7'; AND shoelace_data.sl_name = 'sl7';
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
Step 5 changes <literal>OLD</> references into result relation references: Step 5 changes <literal>OLD</> references into result relation references:
<ProgramListing> <programlisting>
INSERT INTO shoelace_log VALUES ( INSERT INTO shoelace_log VALUES (
shoelace_data.sl_name, 6, shoelace_data.sl_name, 6,
current_user, current_timestamp ) current_user, current_timestamp )
...@@ -1186,7 +1186,7 @@ INSERT INTO shoelace_log VALUES ( ...@@ -1186,7 +1186,7 @@ INSERT INTO shoelace_log VALUES (
shoelace_data shoelace_data shoelace_data shoelace_data
WHERE 6 &lt;&gt; <emphasis>shoelace_data.sl_avail</emphasis> WHERE 6 &lt;&gt; <emphasis>shoelace_data.sl_avail</emphasis>
AND shoelace_data.sl_name = 'sl7'; AND shoelace_data.sl_name = 'sl7';
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
...@@ -1194,7 +1194,7 @@ INSERT INTO shoelace_log VALUES ( ...@@ -1194,7 +1194,7 @@ INSERT INTO shoelace_log VALUES (
original query tree. In short, the output from the rule system original query tree. In short, the output from the rule system
is a list of two query trees that correspond to these statements: is a list of two query trees that correspond to these statements:
<ProgramListing> <programlisting>
INSERT INTO shoelace_log VALUES ( INSERT INTO shoelace_log VALUES (
shoelace_data.sl_name, 6, shoelace_data.sl_name, 6,
current_user, current_timestamp ) current_user, current_timestamp )
...@@ -1204,7 +1204,7 @@ INSERT INTO shoelace_log VALUES ( ...@@ -1204,7 +1204,7 @@ INSERT INTO shoelace_log VALUES (
UPDATE shoelace_data SET sl_avail = 6 UPDATE shoelace_data SET sl_avail = 6
WHERE sl_name = 'sl7'; WHERE sl_name = 'sl7';
</ProgramListing> </programlisting>
These are executed in this order, and that is exactly what These are executed in this order, and that is exactly what
the rule was meant to do. the rule was meant to do.
...@@ -1214,10 +1214,10 @@ UPDATE shoelace_data SET sl_avail = 6 ...@@ -1214,10 +1214,10 @@ UPDATE shoelace_data SET sl_avail = 6
The substitutions and the added qualifications The substitutions and the added qualifications
ensure that, if the original query would be, say, ensure that, if the original query would be, say,
<ProgramListing> <programlisting>
UPDATE shoelace_data SET sl_color = 'green' UPDATE shoelace_data SET sl_color = 'green'
WHERE sl_name = 'sl7'; WHERE sl_name = 'sl7';
</ProgramListing> </programlisting>
no log entry would get written. In that case, the original query no log entry would get written. In that case, the original query
tree does not contain a target list entry for tree does not contain a target list entry for
...@@ -1225,14 +1225,14 @@ UPDATE shoelace_data SET sl_color = 'green' ...@@ -1225,14 +1225,14 @@ UPDATE shoelace_data SET sl_color = 'green'
replaced by <literal>shoelace_data.sl_avail</>. Thus, the extra replaced by <literal>shoelace_data.sl_avail</>. Thus, the extra
command generated by the rule is command generated by the rule is
<ProgramListing> <programlisting>
INSERT INTO shoelace_log VALUES ( INSERT INTO shoelace_log VALUES (
shoelace_data.sl_name, <emphasis>shoelace_data.sl_avail</emphasis>, shoelace_data.sl_name, <emphasis>shoelace_data.sl_avail</emphasis>,
current_user, current_timestamp ) current_user, current_timestamp )
FROM shoelace_data FROM shoelace_data
WHERE <emphasis>shoelace_data.sl_avail</emphasis> &lt;&gt; shoelace_data.sl_avail WHERE <emphasis>shoelace_data.sl_avail</emphasis> &lt;&gt; shoelace_data.sl_avail
AND shoelace_data.sl_name = 'sl7'; AND shoelace_data.sl_name = 'sl7';
</ProgramListing> </programlisting>
and that qualification will never be true. and that qualification will never be true.
</para> </para>
...@@ -1241,59 +1241,59 @@ INSERT INTO shoelace_log VALUES ( ...@@ -1241,59 +1241,59 @@ INSERT INTO shoelace_log VALUES (
It will also work if the original query modifies multiple rows. So It will also work if the original query modifies multiple rows. So
if someone issued the command if someone issued the command
<ProgramListing> <programlisting>
UPDATE shoelace_data SET sl_avail = 0 UPDATE shoelace_data SET sl_avail = 0
WHERE sl_color = 'black'; WHERE sl_color = 'black';
</ProgramListing> </programlisting>
four rows in fact get updated (<literal>sl1</>, <literal>sl2</>, <literal>sl3</>, and <literal>sl4</>). four rows in fact get updated (<literal>sl1</>, <literal>sl2</>, <literal>sl3</>, and <literal>sl4</>).
But <literal>sl3</> already has <literal>sl_avail = 0</>. In this case, the original But <literal>sl3</> already has <literal>sl_avail = 0</>. In this case, the original
query trees qualification is different and that results query trees qualification is different and that results
in the extra query tree in the extra query tree
<ProgramListing> <programlisting>
INSERT INTO shoelace_log INSERT INTO shoelace_log
SELECT shoelace_data.sl_name, 0, SELECT shoelace_data.sl_name, 0,
current_user, current_timestamp current_user, current_timestamp
FROM shoelace_data FROM shoelace_data
WHERE 0 &lt;&gt; shoelace_data.sl_avail WHERE 0 &lt;&gt; shoelace_data.sl_avail
AND <emphasis>shoelace_data.sl_color = 'black'</emphasis>; AND <emphasis>shoelace_data.sl_color = 'black'</emphasis>;
</ProgramListing> </programlisting>
being generated by the rule. This query tree will surely insert being generated by the rule. This query tree will surely insert
three new log entries. And that's absolutely correct. three new log entries. And that's absolutely correct.
</Para> </para>
<Para> <para>
Here we can see why it is important that the original query tree Here we can see why it is important that the original query tree
is executed last. If the <command>UPDATE</command> had been is executed last. If the <command>UPDATE</command> had been
executed first, all the rows would have already been set to zero, so the executed first, all the rows would have already been set to zero, so the
logging <command>INSERT</command> would not find any row where logging <command>INSERT</command> would not find any row where
<literal>0 &lt;&gt; shoelace_data.sl_avail</literal>. <literal>0 &lt;&gt; shoelace_data.sl_avail</literal>.
</Para> </para>
</Sect3> </sect3>
</Sect2> </sect2>
<Sect2 id="rules-update-views"> <sect2 id="rules-update-views">
<Title>Cooperation with Views</Title> <title>Cooperation with Views</title>
<indexterm zone="rules-update-views"><primary>view</><secondary>updating</></> <indexterm zone="rules-update-views"><primary>view</><secondary>updating</></>
<Para> <para>
A simple way to protect view relations from the mentioned A simple way to protect view relations from the mentioned
possibility that someone can try to run <command>INSERT</command>, possibility that someone can try to run <command>INSERT</command>,
<command>UPDATE</command>, or <command>DELETE</command> on them is <command>UPDATE</command>, or <command>DELETE</command> on them is
to let those query trees get thrown away. So we create the rules to let those query trees get thrown away. So we create the rules
<ProgramListing> <programlisting>
CREATE RULE shoe_ins_protect AS ON INSERT TO shoe CREATE RULE shoe_ins_protect AS ON INSERT TO shoe
DO INSTEAD NOTHING; DO INSTEAD NOTHING;
CREATE RULE shoe_upd_protect AS ON UPDATE TO shoe CREATE RULE shoe_upd_protect AS ON UPDATE TO shoe
DO INSTEAD NOTHING; DO INSTEAD NOTHING;
CREATE RULE shoe_del_protect AS ON DELETE TO shoe CREATE RULE shoe_del_protect AS ON DELETE TO shoe
DO INSTEAD NOTHING; DO INSTEAD NOTHING;
</ProgramListing> </programlisting>
If someone now tries to do any of these operations on the view If someone now tries to do any of these operations on the view
relation <literal>shoe</literal>, the rule system will relation <literal>shoe</literal>, the rule system will
...@@ -1302,16 +1302,16 @@ CREATE RULE shoe_del_protect AS ON DELETE TO shoe ...@@ -1302,16 +1302,16 @@ CREATE RULE shoe_del_protect AS ON DELETE TO shoe
query trees will be empty and the whole query will become query trees will be empty and the whole query will become
nothing because there is nothing left to be optimized or nothing because there is nothing left to be optimized or
executed after the rule system is done with it. executed after the rule system is done with it.
</Para> </para>
<Para> <para>
A more sophisticated way to use the rule system is to A more sophisticated way to use the rule system is to
create rules that rewrite the query tree into one that create rules that rewrite the query tree into one that
does the right operation on the real tables. To do that does the right operation on the real tables. To do that
on the <literal>shoelace</literal> view, we create on the <literal>shoelace</literal> view, we create
the following rules: the following rules:
<ProgramListing> <programlisting>
CREATE RULE shoelace_ins AS ON INSERT TO shoelace CREATE RULE shoelace_ins AS ON INSERT TO shoelace
DO INSTEAD DO INSTEAD
INSERT INTO shoelace_data VALUES ( INSERT INTO shoelace_data VALUES (
...@@ -1336,7 +1336,7 @@ CREATE RULE shoelace_del AS ON DELETE TO shoelace ...@@ -1336,7 +1336,7 @@ CREATE RULE shoelace_del AS ON DELETE TO shoelace
DO INSTEAD DO INSTEAD
DELETE FROM shoelace_data DELETE FROM shoelace_data
WHERE sl_name = OLD.sl_name; WHERE sl_name = OLD.sl_name;
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
...@@ -1347,7 +1347,7 @@ CREATE RULE shoelace_del AS ON DELETE TO shoelace ...@@ -1347,7 +1347,7 @@ CREATE RULE shoelace_del AS ON DELETE TO shoelace
insert the items from the part list, and one with a special insert the items from the part list, and one with a special
trick. The creation commands for these are: trick. The creation commands for these are:
<ProgramListing> <programlisting>
CREATE TABLE shoelace_arrive ( CREATE TABLE shoelace_arrive (
arr_name text, arr_name text,
arr_quant integer arr_quant integer
...@@ -1363,12 +1363,12 @@ CREATE RULE shoelace_ok_ins AS ON INSERT TO shoelace_ok ...@@ -1363,12 +1363,12 @@ CREATE RULE shoelace_ok_ins AS ON INSERT TO shoelace_ok
UPDATE shoelace UPDATE shoelace
SET sl_avail = sl_avail + NEW.ok_quant SET sl_avail = sl_avail + NEW.ok_quant
WHERE sl_name = NEW.ok_name; WHERE sl_name = NEW.ok_name;
</ProgramListing> </programlisting>
Now you can fill the table <literal>shoelace_arrive</literal> with Now you can fill the table <literal>shoelace_arrive</literal> with
the data from the parts list: the data from the parts list:
<ProgramListing> <programlisting>
SELECT * FROM shoelace_arrive; SELECT * FROM shoelace_arrive;
arr_name | arr_quant arr_name | arr_quant
...@@ -1377,11 +1377,11 @@ SELECT * FROM shoelace_arrive; ...@@ -1377,11 +1377,11 @@ SELECT * FROM shoelace_arrive;
sl6 | 20 sl6 | 20
sl8 | 20 sl8 | 20
(3 rows) (3 rows)
</ProgramListing> </programlisting>
Take a quick look at the current data: Take a quick look at the current data:
<ProgramListing> <programlisting>
SELECT * FROM shoelace; SELECT * FROM shoelace;
sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
...@@ -1395,17 +1395,17 @@ SELECT * FROM shoelace; ...@@ -1395,17 +1395,17 @@ SELECT * FROM shoelace;
sl5 | 4 | brown | 1 | m | 100 sl5 | 4 | brown | 1 | m | 100
sl6 | 0 | brown | 0.9 | m | 90 sl6 | 0 | brown | 0.9 | m | 90
(8 rows) (8 rows)
</ProgramListing> </programlisting>
Now move the arrived shoelaces in: Now move the arrived shoelaces in:
<ProgramListing> <programlisting>
INSERT INTO shoelace_ok SELECT * FROM shoelace_arrive; INSERT INTO shoelace_ok SELECT * FROM shoelace_arrive;
</ProgramListing> </programlisting>
and check the results: and check the results:
<ProgramListing> <programlisting>
SELECT * FROM shoelace ORDER BY sl_name; SELECT * FROM shoelace ORDER BY sl_name;
sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
...@@ -1429,7 +1429,7 @@ SELECT * FROM shoelace_log; ...@@ -1429,7 +1429,7 @@ SELECT * FROM shoelace_log;
sl6 | 20 | Al | Tue Oct 20 19:25:16 1998 MET DST sl6 | 20 | Al | Tue Oct 20 19:25:16 1998 MET DST
sl8 | 21 | Al | Tue Oct 20 19:25:16 1998 MET DST sl8 | 21 | Al | Tue Oct 20 19:25:16 1998 MET DST
(4 rows) (4 rows)
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
...@@ -1438,30 +1438,30 @@ SELECT * FROM shoelace_log; ...@@ -1438,30 +1438,30 @@ SELECT * FROM shoelace_log;
transformation will be the last in this chapter. First, there is transformation will be the last in this chapter. First, there is
the parser's output the parser's output
<ProgramListing> <programlisting>
INSERT INTO shoelace_ok INSERT INTO shoelace_ok
SELECT shoelace_arrive.arr_name, shoelace_arrive.arr_quant SELECT shoelace_arrive.arr_name, shoelace_arrive.arr_quant
FROM shoelace_arrive shoelace_arrive, shoelace_ok shoelace_ok; FROM shoelace_arrive shoelace_arrive, shoelace_ok shoelace_ok;
</ProgramListing> </programlisting>
Now the first rule <literal>shoelace_ok_ins</literal> is applied and turns this Now the first rule <literal>shoelace_ok_ins</literal> is applied and turns this
into into
<ProgramListing> <programlisting>
UPDATE shoelace UPDATE shoelace
SET sl_avail = shoelace.sl_avail + shoelace_arrive.arr_quant SET sl_avail = shoelace.sl_avail + shoelace_arrive.arr_quant
FROM shoelace_arrive shoelace_arrive, shoelace_ok shoelace_ok, FROM shoelace_arrive shoelace_arrive, shoelace_ok shoelace_ok,
shoelace_ok *OLD*, shoelace_ok *NEW*, shoelace_ok *OLD*, shoelace_ok *NEW*,
shoelace shoelace shoelace shoelace
WHERE shoelace.sl_name = shoelace_arrive.arr_name; WHERE shoelace.sl_name = shoelace_arrive.arr_name;
</ProgramListing> </programlisting>
and throws away the original <command>INSERT</command> on and throws away the original <command>INSERT</command> on
<literal>shoelace_ok</literal>. This rewritten query is passed to <literal>shoelace_ok</literal>. This rewritten query is passed to
the rule system again, and the second applied rule the rule system again, and the second applied rule
<literal>shoelace_upd</literal> produces <literal>shoelace_upd</literal> produces
<ProgramListing> <programlisting>
UPDATE shoelace_data UPDATE shoelace_data
SET sl_name = shoelace.sl_name, SET sl_name = shoelace.sl_name,
sl_avail = shoelace.sl_avail + shoelace_arrive.arr_quant, sl_avail = shoelace.sl_avail + shoelace_arrive.arr_quant,
...@@ -1474,14 +1474,14 @@ UPDATE shoelace_data ...@@ -1474,14 +1474,14 @@ UPDATE shoelace_data
shoelace *NEW*, shoelace_data shoelace_data shoelace *NEW*, shoelace_data shoelace_data
WHERE shoelace.sl_name = shoelace_arrive.arr_name WHERE shoelace.sl_name = shoelace_arrive.arr_name
AND shoelace_data.sl_name = shoelace.sl_name; AND shoelace_data.sl_name = shoelace.sl_name;
</ProgramListing> </programlisting>
Again it's an <literal>INSTEAD</> rule and the previous query tree is trashed. Again it's an <literal>INSTEAD</> rule and the previous query tree is trashed.
Note that this query still uses the view <literal>shoelace</literal>. Note that this query still uses the view <literal>shoelace</literal>.
But the rule system isn't finished with this step, so it continues But the rule system isn't finished with this step, so it continues
and applies the <literal>_RETURN</literal> rule on it, and we get and applies the <literal>_RETURN</literal> rule on it, and we get
<ProgramListing> <programlisting>
UPDATE shoelace_data UPDATE shoelace_data
SET sl_name = s.sl_name, SET sl_name = s.sl_name,
sl_avail = s.sl_avail + shoelace_arrive.arr_quant, sl_avail = s.sl_avail + shoelace_arrive.arr_quant,
...@@ -1496,12 +1496,12 @@ UPDATE shoelace_data ...@@ -1496,12 +1496,12 @@ UPDATE shoelace_data
shoelace_data s, unit u shoelace_data s, unit u
WHERE s.sl_name = shoelace_arrive.arr_name WHERE s.sl_name = shoelace_arrive.arr_name
AND shoelace_data.sl_name = s.sl_name; AND shoelace_data.sl_name = s.sl_name;
</ProgramListing> </programlisting>
Finally, the rule <literal>log_shoelace</literal> gets applied, Finally, the rule <literal>log_shoelace</literal> gets applied,
producing the extra query tree producing the extra query tree
<ProgramListing> <programlisting>
INSERT INTO shoelace_log INSERT INTO shoelace_log
SELECT s.sl_name, SELECT s.sl_name,
s.sl_avail + shoelace_arrive.arr_quant, s.sl_avail + shoelace_arrive.arr_quant,
...@@ -1518,7 +1518,7 @@ SELECT s.sl_name, ...@@ -1518,7 +1518,7 @@ SELECT s.sl_name,
WHERE s.sl_name = shoelace_arrive.arr_name WHERE s.sl_name = shoelace_arrive.arr_name
AND shoelace_data.sl_name = s.sl_name AND shoelace_data.sl_name = s.sl_name
AND (s.sl_avail + shoelace_arrive.arr_quant) &lt;&gt; s.sl_avail; AND (s.sl_avail + shoelace_arrive.arr_quant) &lt;&gt; s.sl_avail;
</ProgramListing> </programlisting>
After that the rule system runs out of rules and returns the After that the rule system runs out of rules and returns the
generated query trees. generated query trees.
...@@ -1526,9 +1526,9 @@ SELECT s.sl_name, ...@@ -1526,9 +1526,9 @@ SELECT s.sl_name,
<para> <para>
So we end up with two final query trees that are equivalent to the So we end up with two final query trees that are equivalent to the
<Acronym>SQL</Acronym> statements <acronym>SQL</acronym> statements
<ProgramListing> <programlisting>
INSERT INTO shoelace_log INSERT INTO shoelace_log
SELECT s.sl_name, SELECT s.sl_name,
s.sl_avail + shoelace_arrive.arr_quant, s.sl_avail + shoelace_arrive.arr_quant,
...@@ -1547,15 +1547,15 @@ UPDATE shoelace_data ...@@ -1547,15 +1547,15 @@ UPDATE shoelace_data
shoelace_data s shoelace_data s
WHERE s.sl_name = shoelace_arrive.sl_name WHERE s.sl_name = shoelace_arrive.sl_name
AND shoelace_data.sl_name = s.sl_name; AND shoelace_data.sl_name = s.sl_name;
</ProgramListing> </programlisting>
The result is that data coming from one relation inserted into another, The result is that data coming from one relation inserted into another,
changed into updates on a third, changed into updating changed into updates on a third, changed into updating
a fourth plus logging that final update in a fifth a fourth plus logging that final update in a fifth
gets reduced into two queries. gets reduced into two queries.
</Para> </para>
<Para> <para>
There is a little detail that's a bit ugly. Looking at the two There is a little detail that's a bit ugly. Looking at the two
queries, it turns out that the <literal>shoelace_data</literal> queries, it turns out that the <literal>shoelace_data</literal>
relation appears twice in the range table where it could relation appears twice in the range table where it could
...@@ -1593,63 +1593,63 @@ Merge Join ...@@ -1593,63 +1593,63 @@ Merge Join
necessary. And the same redundant scan is done once more in the necessary. And the same redundant scan is done once more in the
<command>UPDATE</command>. But it was a really hard job to make <command>UPDATE</command>. But it was a really hard job to make
that all possible at all. that all possible at all.
</Para> </para>
<Para> <para>
Now we make a final demonstration of the Now we make a final demonstration of the
<ProductName>PostgreSQL</ProductName> rule system and its power. <productname>PostgreSQL</productname> rule system and its power.
Say you add some shoelaces with extraordinary colors to your Say you add some shoelaces with extraordinary colors to your
database: database:
<ProgramListing> <programlisting>
INSERT INTO shoelace VALUES ('sl9', 0, 'pink', 35.0, 'inch', 0.0); INSERT INTO shoelace VALUES ('sl9', 0, 'pink', 35.0, 'inch', 0.0);
INSERT INTO shoelace VALUES ('sl10', 1000, 'magenta', 40.0, 'inch', 0.0); INSERT INTO shoelace VALUES ('sl10', 1000, 'magenta', 40.0, 'inch', 0.0);
</ProgramListing> </programlisting>
We would like to make a view to check which We would like to make a view to check which
<literal>shoelace</literal> entries do not fit any shoe in color. <literal>shoelace</literal> entries do not fit any shoe in color.
The view for this is The view for this is
<ProgramListing> <programlisting>
CREATE VIEW shoelace_mismatch AS CREATE VIEW shoelace_mismatch AS
SELECT * FROM shoelace WHERE NOT EXISTS SELECT * FROM shoelace WHERE NOT EXISTS
(SELECT shoename FROM shoe WHERE slcolor = sl_color); (SELECT shoename FROM shoe WHERE slcolor = sl_color);
</ProgramListing> </programlisting>
Its output is Its output is
<ProgramListing> <programlisting>
SELECT * FROM shoelace_mismatch; SELECT * FROM shoelace_mismatch;
sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
---------+----------+----------+--------+---------+----------- ---------+----------+----------+--------+---------+-----------
sl9 | 0 | pink | 35 | inch | 88.9 sl9 | 0 | pink | 35 | inch | 88.9
sl10 | 1000 | magenta | 40 | inch | 101.6 sl10 | 1000 | magenta | 40 | inch | 101.6
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
Now we want to set it up so that mismatching shoelaces that are Now we want to set it up so that mismatching shoelaces that are
not in stock are deleted from the database. not in stock are deleted from the database.
To make it a little harder for <ProductName>PostgreSQL</ProductName>, To make it a little harder for <productname>PostgreSQL</productname>,
we don't delete it directly. Instead we create one more view we don't delete it directly. Instead we create one more view
<ProgramListing> <programlisting>
CREATE VIEW shoelace_can_delete AS CREATE VIEW shoelace_can_delete AS
SELECT * FROM shoelace_mismatch WHERE sl_avail = 0; SELECT * FROM shoelace_mismatch WHERE sl_avail = 0;
</ProgramListing> </programlisting>
and do it this way: and do it this way:
<ProgramListing> <programlisting>
DELETE FROM shoelace WHERE EXISTS DELETE FROM shoelace WHERE EXISTS
(SELECT * FROM shoelace_can_delete (SELECT * FROM shoelace_can_delete
WHERE sl_name = shoelace.sl_name); WHERE sl_name = shoelace.sl_name);
</ProgramListing> </programlisting>
<foreignphrase>Voilà</foreignphrase>: <foreignphrase>Voilà</foreignphrase>:
<ProgramListing> <programlisting>
SELECT * FROM shoelace; SELECT * FROM shoelace;
sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
...@@ -1664,7 +1664,7 @@ SELECT * FROM shoelace; ...@@ -1664,7 +1664,7 @@ SELECT * FROM shoelace;
sl5 | 4 | brown | 1 | m | 100 sl5 | 4 | brown | 1 | m | 100
sl6 | 20 | brown | 0.9 | m | 90 sl6 | 20 | brown | 0.9 | m | 90
(9 rows) (9 rows)
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
...@@ -1675,19 +1675,19 @@ SELECT * FROM shoelace; ...@@ -1675,19 +1675,19 @@ SELECT * FROM shoelace;
gets rewritten into gets rewritten into
one single query tree that deletes the requested data one single query tree that deletes the requested data
from a real table. from a real table.
</Para> </para>
<Para> <para>
There are probably only a few situations out in the real world There are probably only a few situations out in the real world
where such a construct is necessary. But it makes you feel where such a construct is necessary. But it makes you feel
comfortable that it works. comfortable that it works.
</Para> </para>
</Sect2> </sect2>
</Sect1> </sect1>
<Sect1 id="rules-privileges"> <sect1 id="rules-privileges">
<Title>Rules and Privileges</Title> <title>Rules and Privileges</title>
<indexterm zone="rules-privileges"> <indexterm zone="rules-privileges">
<primary>privilege</primary> <primary>privilege</primary>
...@@ -1699,36 +1699,36 @@ SELECT * FROM shoelace; ...@@ -1699,36 +1699,36 @@ SELECT * FROM shoelace;
<secondary sortas="Sichten">with views</secondary> <secondary sortas="Sichten">with views</secondary>
</indexterm> </indexterm>
<Para> <para>
Due to rewriting of queries by the <ProductName>PostgreSQL</ProductName> Due to rewriting of queries by the <productname>PostgreSQL</productname>
rule system, other tables/views than those used in the original rule system, other tables/views than those used in the original
query get accessed. When update rules are used, this can include write access query get accessed. When update rules are used, this can include write access
to tables. to tables.
</Para> </para>
<Para> <para>
Rewrite rules don't have a separate owner. The owner of Rewrite rules don't have a separate owner. The owner of
a relation (table or view) is automatically the owner of the a relation (table or view) is automatically the owner of the
rewrite rules that are defined for it. rewrite rules that are defined for it.
The <ProductName>PostgreSQL</ProductName> rule system changes the The <productname>PostgreSQL</productname> rule system changes the
behavior of the default access control system. Relations that behavior of the default access control system. Relations that
are used due to rules get checked against the are used due to rules get checked against the
privileges of the rule owner, not the user invoking the rule. privileges of the rule owner, not the user invoking the rule.
This means that a user only needs the required privileges This means that a user only needs the required privileges
for the tables/views that he names explicitly in his queries. for the tables/views that he names explicitly in his queries.
</Para> </para>
<Para> <para>
For example: A user has a list of phone numbers where some of For example: A user has a list of phone numbers where some of
them are private, the others are of interest for the secretary of the office. them are private, the others are of interest for the secretary of the office.
He can construct the following: He can construct the following:
<ProgramListing> <programlisting>
CREATE TABLE phone_data (person text, phone text, private boolean); CREATE TABLE phone_data (person text, phone text, private boolean);
CREATE VIEW phone_number AS CREATE VIEW phone_number AS
SELECT person, phone FROM phone_data WHERE NOT private; SELECT person, phone FROM phone_data WHERE NOT private;
GRANT SELECT ON phone_number TO secretary; GRANT SELECT ON phone_number TO secretary;
</ProgramListing> </programlisting>
Nobody except him (and the database superusers) can access the Nobody except him (and the database superusers) can access the
<literal>phone_data</> table. But because of the <command>GRANT</>, <literal>phone_data</> table. But because of the <command>GRANT</>,
...@@ -1744,9 +1744,9 @@ GRANT SELECT ON phone_number TO secretary; ...@@ -1744,9 +1744,9 @@ GRANT SELECT ON phone_number TO secretary;
<literal>phone_number</> is also performed, but this is done <literal>phone_number</> is also performed, but this is done
against the invoking user, so nobody but the user and the against the invoking user, so nobody but the user and the
secretary can use it. secretary can use it.
</Para> </para>
<Para> <para>
The privileges are checked rule by rule. So the secretary is for now the The privileges are checked rule by rule. So the secretary is for now the
only one who can see the public phone numbers. But the secretary can setup only one who can see the public phone numbers. But the secretary can setup
another view and grant access to that to the public. Then, anyone another view and grant access to that to the public. Then, anyone
...@@ -1757,9 +1757,9 @@ GRANT SELECT ON phone_number TO secretary; ...@@ -1757,9 +1757,9 @@ GRANT SELECT ON phone_number TO secretary;
And as soon as the user will notice, that the secretary opened And as soon as the user will notice, that the secretary opened
his <literal>phone_number</> view, he can revoke his access. Immediately, any his <literal>phone_number</> view, he can revoke his access. Immediately, any
access to the secretary's view would fail. access to the secretary's view would fail.
</Para> </para>
<Para> <para>
One might think that this rule-by-rule checking is a security One might think that this rule-by-rule checking is a security
hole, but in fact it isn't. But if it did not work this way, the secretary hole, but in fact it isn't. But if it did not work this way, the secretary
could set up a table with the same columns as <literal>phone_number</> and could set up a table with the same columns as <literal>phone_number</> and
...@@ -1768,9 +1768,9 @@ GRANT SELECT ON phone_number TO secretary; ...@@ -1768,9 +1768,9 @@ GRANT SELECT ON phone_number TO secretary;
<command>GRANT</command> command means, <quote>I trust you</quote>. <command>GRANT</command> command means, <quote>I trust you</quote>.
If someone you trust does the thing above, it's time to If someone you trust does the thing above, it's time to
think it over and then use <command>REVOKE</command>. think it over and then use <command>REVOKE</command>.
</Para> </para>
<Para> <para>
This mechanism also works for update rules. In the examples of This mechanism also works for update rules. In the examples of
the previous section, the owner of the tables in the example the previous section, the owner of the tables in the example
database could grant the privileges <literal>SELECT</>, database could grant the privileges <literal>SELECT</>,
...@@ -1780,20 +1780,20 @@ GRANT SELECT ON phone_number TO secretary; ...@@ -1780,20 +1780,20 @@ GRANT SELECT ON phone_number TO secretary;
write log entries will still be executed successfully, and that write log entries will still be executed successfully, and that
other user could see the log entries. But he cannot create fake other user could see the log entries. But he cannot create fake
entries, nor could he manipulate or remove existing ones. entries, nor could he manipulate or remove existing ones.
</Para> </para>
</Sect1> </sect1>
<Sect1 id="rules-status"> <sect1 id="rules-status">
<Title>Rules and Command Status</Title> <title>Rules and Command Status</title>
<Para> <para>
The <ProductName>PostgreSQL</ProductName> server returns a command The <productname>PostgreSQL</productname> server returns a command
status string, such as <literal>INSERT 149592 1</>, for each status string, such as <literal>INSERT 149592 1</>, for each
command it receives. This is simple enough when there are no rules command it receives. This is simple enough when there are no rules
involved, but what happens when the query is rewritten by rules? involved, but what happens when the query is rewritten by rules?
</Para> </para>
<Para> <para>
Rules affect the command status as follows: Rules affect the command status as follows:
<itemizedlist> <itemizedlist>
...@@ -1828,18 +1828,18 @@ GRANT SELECT ON phone_number TO secretary; ...@@ -1828,18 +1828,18 @@ GRANT SELECT ON phone_number TO secretary;
(This system was established in <productname>PostgreSQL</> 7.3. (This system was established in <productname>PostgreSQL</> 7.3.
In versions before that, the command status might show different In versions before that, the command status might show different
results when rules exist.) results when rules exist.)
</Para> </para>
<Para> <para>
The programmer can ensure that any desired <literal>INSTEAD</> rule is the one The programmer can ensure that any desired <literal>INSTEAD</> rule is the one
that sets the command status in the second case, by giving it the that sets the command status in the second case, by giving it the
alphabetically last rule name among the active rules, so that it alphabetically last rule name among the active rules, so that it
gets applied last. gets applied last.
</Para> </para>
</Sect1> </sect1>
<Sect1 id="rules-triggers"> <sect1 id="rules-triggers">
<Title>Rules versus Triggers</Title> <title>Rules versus Triggers</title>
<indexterm zone="rules-triggers"> <indexterm zone="rules-triggers">
<primary>rule</primary> <primary>rule</primary>
...@@ -1851,9 +1851,9 @@ GRANT SELECT ON phone_number TO secretary; ...@@ -1851,9 +1851,9 @@ GRANT SELECT ON phone_number TO secretary;
<secondary sortas="Regeln">compared with rules</secondary> <secondary sortas="Regeln">compared with rules</secondary>
</indexterm> </indexterm>
<Para> <para>
Many things that can be done using triggers can also be Many things that can be done using triggers can also be
implemented using the <ProductName>PostgreSQL</ProductName> implemented using the <productname>PostgreSQL</productname>
rule system. One of the things that cannot be implemented by rule system. One of the things that cannot be implemented by
rules are some kinds of constraints, especially foreign keys. It is possible rules are some kinds of constraints, especially foreign keys. It is possible
to place a qualified rule that rewrites a command to <literal>NOTHING</> to place a qualified rule that rewrites a command to <literal>NOTHING</>
...@@ -1862,9 +1862,9 @@ GRANT SELECT ON phone_number TO secretary; ...@@ -1862,9 +1862,9 @@ GRANT SELECT ON phone_number TO secretary;
not a good idea. If checks for valid values are required, not a good idea. If checks for valid values are required,
and in the case of an invalid value an error message should and in the case of an invalid value an error message should
be generated, it must be done by a trigger. be generated, it must be done by a trigger.
</Para> </para>
<Para> <para>
On the other hand, a trigger that is fired on On the other hand, a trigger that is fired on
<command>INSERT</command> on a view can do the same as a rule: put <command>INSERT</command> on a view can do the same as a rule: put
the data somewhere else and suppress the insert in the view. But the data somewhere else and suppress the insert in the view. But
...@@ -1872,9 +1872,9 @@ GRANT SELECT ON phone_number TO secretary; ...@@ -1872,9 +1872,9 @@ GRANT SELECT ON phone_number TO secretary;
<command>DELETE</command>, because there is no real data in the <command>DELETE</command>, because there is no real data in the
view relation that could be scanned, and thus the trigger would view relation that could be scanned, and thus the trigger would
never get called. Only a rule will help. never get called. Only a rule will help.
</Para> </para>
<Para> <para>
For the things that can be implemented by both, which is best For the things that can be implemented by both, which is best
depends on the usage of the database. depends on the usage of the database.
A trigger is fired for any affected row once. A rule manipulates A trigger is fired for any affected row once. A rule manipulates
...@@ -1884,13 +1884,13 @@ GRANT SELECT ON phone_number TO secretary; ...@@ -1884,13 +1884,13 @@ GRANT SELECT ON phone_number TO secretary;
called for every single row and must execute its operations called for every single row and must execute its operations
many times. However, the trigger approach is conceptually far many times. However, the trigger approach is conceptually far
simpler than the rule approach, and is easier for novices to get right. simpler than the rule approach, and is easier for novices to get right.
</Para> </para>
<Para> <para>
Here we show an example of how the choice of rules versus triggers Here we show an example of how the choice of rules versus triggers
plays out in one situation. There are two tables: plays out in one situation. There are two tables:
<ProgramListing> <programlisting>
CREATE TABLE computer ( CREATE TABLE computer (
hostname text, -- indexed hostname text, -- indexed
manufacturer text -- indexed manufacturer text -- indexed
...@@ -1900,43 +1900,43 @@ CREATE TABLE software ( ...@@ -1900,43 +1900,43 @@ CREATE TABLE software (
software text, -- indexed software text, -- indexed
hostname text -- indexed hostname text -- indexed
); );
</ProgramListing> </programlisting>
Both tables have many thousands of rows and the indexes on Both tables have many thousands of rows and the indexes on
<structfield>hostname</> are unique. The rule or trigger should <structfield>hostname</> are unique. The rule or trigger should
implement a constraint that deletes rows from <literal>software</> implement a constraint that deletes rows from <literal>software</>
that reference a deleted computer. The trigger would use this command: that reference a deleted computer. The trigger would use this command:
<ProgramListing> <programlisting>
DELETE FROM software WHERE hostname = $1; DELETE FROM software WHERE hostname = $1;
</ProgramListing> </programlisting>
Since the trigger is called for each individual row deleted from Since the trigger is called for each individual row deleted from
<literal>computer</>, it can prepare and save the plan for this <literal>computer</>, it can prepare and save the plan for this
command and pass the <structfield>hostname</> value in the command and pass the <structfield>hostname</> value in the
parameter. The rule would be written as parameter. The rule would be written as
<ProgramListing> <programlisting>
CREATE RULE computer_del AS ON DELETE TO computer CREATE RULE computer_del AS ON DELETE TO computer
DO DELETE FROM software WHERE hostname = OLD.hostname; DO DELETE FROM software WHERE hostname = OLD.hostname;
</ProgramListing> </programlisting>
</para> </para>
<para> <para>
Now we look at different types of deletes. In the case of a Now we look at different types of deletes. In the case of a
<ProgramListing> <programlisting>
DELETE FROM computer WHERE hostname = 'mypc.local.net'; DELETE FROM computer WHERE hostname = 'mypc.local.net';
</ProgramListing> </programlisting>
the table <literal>computer</> is scanned by index (fast), and the the table <literal>computer</> is scanned by index (fast), and the
command issued by the trigger would also use an index scan (also fast). command issued by the trigger would also use an index scan (also fast).
The extra command from the rule would be The extra command from the rule would be
<ProgramListing> <programlisting>
DELETE FROM software WHERE computer.hostname = 'mypc.local.net' DELETE FROM software WHERE computer.hostname = 'mypc.local.net'
AND software.hostname = computer.hostname; AND software.hostname = computer.hostname;
</ProgramListing> </programlisting>
Since there are appropriate indexes setup, the planner Since there are appropriate indexes setup, the planner
will create a plan of will create a plan of
...@@ -1957,17 +1957,17 @@ Nestloop ...@@ -1957,17 +1957,17 @@ Nestloop
<literal>old</>. There are two possible commands to do that. One <literal>old</>. There are two possible commands to do that. One
is is
<ProgramListing> <programlisting>
DELETE FROM computer WHERE hostname &gt;= 'old' DELETE FROM computer WHERE hostname &gt;= 'old'
AND hostname &lt; 'ole' AND hostname &lt; 'ole'
</ProgramListing> </programlisting>
The command added by the rule will be The command added by the rule will be
<ProgramListing> <programlisting>
DELETE FROM software WHERE computer.hostname &gt;= 'old' AND computer.hostname &lt; 'ole' DELETE FROM software WHERE computer.hostname &gt;= 'old' AND computer.hostname &lt; 'ole'
AND software.hostname = computer.hostname; AND software.hostname = computer.hostname;
</ProgramListing> </programlisting>
with the plan with the plan
...@@ -1980,9 +1980,9 @@ Hash Join ...@@ -1980,9 +1980,9 @@ Hash Join
The other possible command is The other possible command is
<ProgramListing> <programlisting>
DELETE FROM computer WHERE hostname ~ '^old'; DELETE FROM computer WHERE hostname ~ '^old';
</ProgramListing> </programlisting>
which results in the following executing plan for the command which results in the following executing plan for the command
added by the rule: added by the rule:
...@@ -2007,44 +2007,44 @@ Nestloop ...@@ -2007,44 +2007,44 @@ Nestloop
the table <literal>software</> whether the rule will still be faster in the the table <literal>software</> whether the rule will still be faster in the
sequential scan situation. 2000 command executions from the trigger over the SPI sequential scan situation. 2000 command executions from the trigger over the SPI
manager take some time, even if all the index blocks will soon be in the cache. manager take some time, even if all the index blocks will soon be in the cache.
</Para> </para>
<Para> <para>
The last command we look at is The last command we look at is
<ProgramListing> <programlisting>
DELETE FROM computer WHERE manufacurer = 'bim'; DELETE FROM computer WHERE manufacurer = 'bim';
</ProgramListing> </programlisting>
Again this could result in many rows to be deleted from Again this could result in many rows to be deleted from
<literal>computer</>. So the trigger will again run many commands <literal>computer</>. So the trigger will again run many commands
through the executor. The command generated by the rule will be through the executor. The command generated by the rule will be
<ProgramListing> <programlisting>
DELETE FROM software WHERE computer.manufacurer = 'bim' DELETE FROM software WHERE computer.manufacurer = 'bim'
AND software.hostname = computer.hostname; AND software.hostname = computer.hostname;
</ProgramListing> </programlisting>
The plan for that command will again be the nested loop over two The plan for that command will again be the nested loop over two
index scans, only using a different index on <literal>computer</>: index scans, only using a different index on <literal>computer</>:
<ProgramListing> <programlisting>
Nestloop Nestloop
-&gt; Index Scan using comp_manufidx on computer -&gt; Index Scan using comp_manufidx on computer
-&gt; Index Scan using soft_hostidx on software -&gt; Index Scan using soft_hostidx on software
</ProgramListing> </programlisting>
In any of these cases, the extra commands from the rule system In any of these cases, the extra commands from the rule system
will be more or less independent from the number of affected rows will be more or less independent from the number of affected rows
in a command. in a command.
</Para> </para>
<![IGNORE[ <![IGNORE[
<!-- What's happening with this? If it doesn't come back, remove this section. --> <!-- What's happening with this? If it doesn't come back, remove this section. -->
<Para> <para>
Another situation is cases on <command>UPDATE</command> where it depends on the Another situation is cases on <command>UPDATE</command> where it depends on the
change of an attribute if an action should be performed or change of an attribute if an action should be performed or
not. In <ProductName>PostgreSQL</ProductName> version 6.4, the not. In <productname>PostgreSQL</productname> version 6.4, the
attribute specification for rule events is disabled (it will have attribute specification for rule events is disabled (it will have
its comeback latest in 6.5, maybe earlier its comeback latest in 6.5, maybe earlier
- stay tuned). So for now the only way to - stay tuned). So for now the only way to
...@@ -2063,17 +2063,17 @@ Nestloop ...@@ -2063,17 +2063,17 @@ Nestloop
target list and will suppress the additional query completely target list and will suppress the additional query completely
if the attribute isn't touched. So the rule, qualified or not, if the attribute isn't touched. So the rule, qualified or not,
will only do its scans if there ever could be something to do. will only do its scans if there ever could be something to do.
</Para> </para>
]]> ]]>
<Para> <para>
The summary is, rules will only be significantly slower than The summary is, rules will only be significantly slower than
triggers if their actions result in large and badly qualified triggers if their actions result in large and badly qualified
joins, a situation where the planner fails. joins, a situation where the planner fails.
</Para> </para>
</Sect1> </sect1>
</Chapter> </chapter>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
Local variables: Local variables:
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.302 2005/01/22 22:56:36 momjian Exp $ $PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.303 2005/01/23 00:30:18 momjian Exp $
--> -->
<Chapter Id="runtime"> <chapter Id="runtime">
<Title>Server Run-time Environment</Title> <title>Server Run-time Environment</title>
<Para> <para>
This chapter discusses how to set up and run the database server This chapter discusses how to set up and run the database server
and its interactions with the operating system. and its interactions with the operating system.
</para> </para>
...@@ -447,7 +447,7 @@ psql: could not connect to server: No such file or directory ...@@ -447,7 +447,7 @@ psql: could not connect to server: No such file or directory
</sect1> </sect1>
<sect1 id="runtime-config"> <sect1 id="runtime-config">
<Title>Run-time Configuration</Title> <title>Run-time Configuration</title>
<indexterm> <indexterm>
<primary>configuration</primary> <primary>configuration</primary>
...@@ -4981,7 +4981,7 @@ psql -h localhost -p 3333 template1 ...@@ -4981,7 +4981,7 @@ psql -h localhost -p 3333 template1
</sect1> </sect1>
</Chapter> </chapter>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
Local variables: Local variables:
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/xindex.sgml,v 1.37 2004/11/15 06:32:14 neilc Exp $ $PostgreSQL: pgsql/doc/src/sgml/xindex.sgml,v 1.38 2005/01/23 00:30:18 momjian Exp $
--> -->
<sect1 id="xindex"> <sect1 id="xindex">
...@@ -700,7 +700,7 @@ DEFAULT FOR TYPE int8 USING btree AS ...@@ -700,7 +700,7 @@ DEFAULT FOR TYPE int8 USING btree AS
<note> <note>
<para> <para>
In <ProductName>PostgreSQL</ProductName> versions before 7.4, In <productname>PostgreSQL</productname> versions before 7.4,
sorting and grouping operations would implicitly use operators named sorting and grouping operations would implicitly use operators named
<literal>=</>, <literal>&lt;</>, and <literal>&gt;</>. The new <literal>=</>, <literal>&lt;</>, and <literal>&gt;</>. The new
behavior of relying on default operator classes avoids having to make behavior of relying on default operator classes avoids having to make
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.32 2004/11/15 06:32:14 neilc Exp $ $PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.33 2005/01/23 00:30:18 momjian Exp $
--> -->
<sect1 id="xoper"> <sect1 id="xoper">
...@@ -10,7 +10,7 @@ $PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.32 2004/11/15 06:32:14 neilc Exp ...@@ -10,7 +10,7 @@ $PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.32 2004/11/15 06:32:14 neilc Exp
<secondary>user-defined</secondary> <secondary>user-defined</secondary>
</indexterm> </indexterm>
<Para> <para>
Every operator is <quote>syntactic sugar</quote> for a call to an Every operator is <quote>syntactic sugar</quote> for a call to an
underlying function that does the real work; so you must underlying function that does the real work; so you must
first create the underlying function before you can create first create the underlying function before you can create
...@@ -19,9 +19,9 @@ $PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.32 2004/11/15 06:32:14 neilc Exp ...@@ -19,9 +19,9 @@ $PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.32 2004/11/15 06:32:14 neilc Exp
that helps the query planner optimize queries that use the that helps the query planner optimize queries that use the
operator. The next section will be devoted to explaining operator. The next section will be devoted to explaining
that additional information. that additional information.
</Para> </para>
<Para> <para>
<productname>PostgreSQL</productname> supports left unary, right <productname>PostgreSQL</productname> supports left unary, right
unary, and binary operators. Operators can be unary, and binary operators. Operators can be
overloaded;<indexterm><primary>overloading</primary><secondary>operators</secondary></indexterm> overloaded;<indexterm><primary>overloading</primary><secondary>operators</secondary></indexterm>
...@@ -29,15 +29,15 @@ $PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.32 2004/11/15 06:32:14 neilc Exp ...@@ -29,15 +29,15 @@ $PostgreSQL: pgsql/doc/src/sgml/xoper.sgml,v 1.32 2004/11/15 06:32:14 neilc Exp
that have different numbers and types of operands. When a query is that have different numbers and types of operands. When a query is
executed, the system determines the operator to call from the executed, the system determines the operator to call from the
number and types of the provided operands. number and types of the provided operands.
</Para> </para>
<Para> <para>
Here is an example of creating an operator for adding two complex Here is an example of creating an operator for adding two complex
numbers. We assume we've already created the definition of type numbers. We assume we've already created the definition of type
<type>complex</type> (see <xref linkend="xtypes">). First we need a <type>complex</type> (see <xref linkend="xtypes">). First we need a
function that does the work, then we can define the operator: function that does the work, then we can define the operator:
<ProgramListing> <programlisting>
CREATE FUNCTION complex_add(complex, complex) CREATE FUNCTION complex_add(complex, complex)
RETURNS complex RETURNS complex
AS '<replaceable>filename</replaceable>', 'complex_add' AS '<replaceable>filename</replaceable>', 'complex_add'
...@@ -49,10 +49,10 @@ CREATE OPERATOR + ( ...@@ -49,10 +49,10 @@ CREATE OPERATOR + (
procedure = complex_add, procedure = complex_add,
commutator = + commutator = +
); );
</ProgramListing> </programlisting>
</Para> </para>
<Para> <para>
Now we could execute a query like this: Now we could execute a query like this:
<screen> <screen>
...@@ -63,9 +63,9 @@ SELECT (a + b) AS c FROM test_complex; ...@@ -63,9 +63,9 @@ SELECT (a + b) AS c FROM test_complex;
(5.2,6.05) (5.2,6.05)
(133.42,144.95) (133.42,144.95)
</screen> </screen>
</Para> </para>
<Para> <para>
We've shown how to create a binary operator here. To create unary We've shown how to create a binary operator here. To create unary
operators, just omit one of <literal>leftarg</> (for left unary) or operators, just omit one of <literal>leftarg</> (for left unary) or
<literal>rightarg</> (for right unary). The <literal>procedure</> <literal>rightarg</> (for right unary). The <literal>procedure</>
...@@ -74,14 +74,14 @@ SELECT (a + b) AS c FROM test_complex; ...@@ -74,14 +74,14 @@ SELECT (a + b) AS c FROM test_complex;
clause shown in the example is an optional hint to the query clause shown in the example is an optional hint to the query
optimizer. Further details about <literal>commutator</> and other optimizer. Further details about <literal>commutator</> and other
optimizer hints appear in the next section. optimizer hints appear in the next section.
</Para> </para>
</sect1> </sect1>
<sect1 id="xoper-optimization"> <sect1 id="xoper-optimization">
<title>Operator Optimization Information</title> <title>Operator Optimization Information</title>
<para> <para>
A <ProductName>PostgreSQL</ProductName> operator definition can include A <productname>PostgreSQL</productname> operator definition can include
several optional clauses that tell the system useful things about how several optional clauses that tell the system useful things about how
the operator behaves. These clauses should be provided whenever the operator behaves. These clauses should be provided whenever
appropriate, because they can make for considerable speedups in execution appropriate, because they can make for considerable speedups in execution
...@@ -95,7 +95,7 @@ SELECT (a + b) AS c FROM test_complex; ...@@ -95,7 +95,7 @@ SELECT (a + b) AS c FROM test_complex;
<para> <para>
Additional optimization clauses might be added in future versions of Additional optimization clauses might be added in future versions of
<ProductName>PostgreSQL</ProductName>. The ones described here are all <productname>PostgreSQL</productname>. The ones described here are all
the ones that release &version; understands. the ones that release &version; understands.
</para> </para>
...@@ -115,7 +115,7 @@ SELECT (a + b) AS c FROM test_complex; ...@@ -115,7 +115,7 @@ SELECT (a + b) AS c FROM test_complex;
<para> <para>
The left operand type of a commutable operator is the same as the The left operand type of a commutable operator is the same as the
right operand type of its commutator, and vice versa. So the name of right operand type of its commutator, and vice versa. So the name of
the commutator operator is all that <ProductName>PostgreSQL</ProductName> the commutator operator is all that <productname>PostgreSQL</productname>
needs to be given to look up the commutator, and that's all that needs to needs to be given to look up the commutator, and that's all that needs to
be provided in the <literal>COMMUTATOR</> clause. be provided in the <literal>COMMUTATOR</> clause.
</para> </para>
...@@ -131,7 +131,7 @@ SELECT (a + b) AS c FROM test_complex; ...@@ -131,7 +131,7 @@ SELECT (a + b) AS c FROM test_complex;
index scan unless it can determine how to flip the clause around to index scan unless it can determine how to flip the clause around to
<literal>tab2.y = tab1.x</>, because the index-scan machinery expects <literal>tab2.y = tab1.x</>, because the index-scan machinery expects
to see the indexed column on the left of the operator it is given. to see the indexed column on the left of the operator it is given.
<ProductName>PostgreSQL</ProductName> will <emphasis>not</> simply <productname>PostgreSQL</productname> will <emphasis>not</> simply
assume that this is a valid transformation &mdash; the creator of the assume that this is a valid transformation &mdash; the creator of the
<literal>=</> operator must specify that it is valid, by marking the <literal>=</> operator must specify that it is valid, by marking the
operator with commutator information. operator with commutator information.
...@@ -149,7 +149,7 @@ SELECT (a + b) AS c FROM test_complex; ...@@ -149,7 +149,7 @@ SELECT (a + b) AS c FROM test_complex;
<para> <para>
One way is to omit the <literal>COMMUTATOR</> clause in the first operator that One way is to omit the <literal>COMMUTATOR</> clause in the first operator that
you define, and then provide one in the second operator's definition. you define, and then provide one in the second operator's definition.
Since <ProductName>PostgreSQL</ProductName> knows that commutative Since <productname>PostgreSQL</productname> knows that commutative
operators come in pairs, when it sees the second definition it will operators come in pairs, when it sees the second definition it will
automatically go back and fill in the missing <literal>COMMUTATOR</> clause in automatically go back and fill in the missing <literal>COMMUTATOR</> clause in
the first definition. the first definition.
...@@ -159,12 +159,12 @@ SELECT (a + b) AS c FROM test_complex; ...@@ -159,12 +159,12 @@ SELECT (a + b) AS c FROM test_complex;
<listitem> <listitem>
<para> <para>
The other, more straightforward way is just to include <literal>COMMUTATOR</> clauses The other, more straightforward way is just to include <literal>COMMUTATOR</> clauses
in both definitions. When <ProductName>PostgreSQL</ProductName> processes in both definitions. When <productname>PostgreSQL</productname> processes
the first definition and realizes that <literal>COMMUTATOR</> refers to a nonexistent the first definition and realizes that <literal>COMMUTATOR</> refers to a nonexistent
operator, the system will make a dummy entry for that operator in the operator, the system will make a dummy entry for that operator in the
system catalog. This dummy entry will have valid data only system catalog. This dummy entry will have valid data only
for the operator name, left and right operand types, and result type, for the operator name, left and right operand types, and result type,
since that's all that <ProductName>PostgreSQL</ProductName> can deduce since that's all that <productname>PostgreSQL</productname> can deduce
at this point. The first operator's catalog entry will link to this at this point. The first operator's catalog entry will link to this
dummy entry. Later, when you define the second operator, the system dummy entry. Later, when you define the second operator, the system
updates the dummy entry with the additional information from the second updates the dummy entry with the additional information from the second
...@@ -225,9 +225,9 @@ SELECT (a + b) AS c FROM test_complex; ...@@ -225,9 +225,9 @@ SELECT (a + b) AS c FROM test_complex;
binary operators that return <type>boolean</>. The idea behind a restriction binary operators that return <type>boolean</>. The idea behind a restriction
selectivity estimator is to guess what fraction of the rows in a selectivity estimator is to guess what fraction of the rows in a
table will satisfy a <literal>WHERE</literal>-clause condition of the form table will satisfy a <literal>WHERE</literal>-clause condition of the form
<ProgramListing> <programlisting>
column OP constant column OP constant
</ProgramListing> </programlisting>
for the current operator and a particular constant value. for the current operator and a particular constant value.
This assists the optimizer by This assists the optimizer by
giving it some idea of how many rows will be eliminated by <literal>WHERE</> giving it some idea of how many rows will be eliminated by <literal>WHERE</>
...@@ -297,9 +297,9 @@ column OP constant ...@@ -297,9 +297,9 @@ column OP constant
binary operators that return <type>boolean</type>. The idea behind a join binary operators that return <type>boolean</type>. The idea behind a join
selectivity estimator is to guess what fraction of the rows in a selectivity estimator is to guess what fraction of the rows in a
pair of tables will satisfy a <literal>WHERE</>-clause condition of the form pair of tables will satisfy a <literal>WHERE</>-clause condition of the form
<ProgramListing> <programlisting>
table1.column1 OP table2.column2 table1.column1 OP table2.column2
</ProgramListing> </programlisting>
for the current operator. As with the <literal>RESTRICT</literal> clause, this helps for the current operator. As with the <literal>RESTRICT</literal> clause, this helps
the optimizer very substantially by letting it figure out which the optimizer very substantially by letting it figure out which
of several possible join sequences is likely to take the least work. of several possible join sequences is likely to take the least work.
...@@ -496,7 +496,7 @@ table1.column1 OP table2.column2 ...@@ -496,7 +496,7 @@ table1.column1 OP table2.column2
<note> <note>
<para> <para>
In <ProductName>PostgreSQL</ProductName> versions before 7.3, In <productname>PostgreSQL</productname> versions before 7.3,
the <literal>MERGES</> shorthand was not available: to make a the <literal>MERGES</> shorthand was not available: to make a
merge-joinable operator one had to write both <literal>SORT1</> and merge-joinable operator one had to write both <literal>SORT1</> and
<literal>SORT2</> explicitly. Also, the <literal>LTCMP</> and <literal>SORT2</> explicitly. Also, the <literal>LTCMP</> and
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
document all new features document all new features
update help output from inside the programs update help output from inside the programs
doc/src/sgml/ref manual pages doc/src/sgml/ref manual pages
convert any literal "<" and ">" characters convert any literal "<" and ">" characters, use tools/find_gt_lt
* Ports * Ports
update config.guess and config.sub at the start of beta update config.guess and config.sub at the start of beta
......
grep '[^]a-z0-9"/!-]>' *.sgml ref/*.sgml
grep '<[^]a-z0-9"/!-]' *.sgml ref/*.sgml
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment