Commit c934cf1e authored by Neil Conway's avatar Neil Conway

Add a few more cross-references where appropriate, add more text about

the FROM clause and an example to the UPDATE reference page, and make
a few other SGML tweaks.
parent 9e733eab
<!-- $PostgreSQL: pgsql/doc/src/sgml/queries.sgml,v 1.28 2003/11/29 19:51:37 pgsql Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/queries.sgml,v 1.29 2004/03/03 22:22:24 neilc Exp $ -->
<chapter id="queries"> <chapter id="queries">
<title>Queries</title> <title>Queries</title>
...@@ -108,8 +108,9 @@ SELECT random(); ...@@ -108,8 +108,9 @@ SELECT random();
<title>The <literal>FROM</literal> Clause</title> <title>The <literal>FROM</literal> Clause</title>
<para> <para>
The <literal>FROM</> clause derives a table from one or more other The <xref linkend="sql-from" endterm="sql-from-title"> derives a
tables given in a comma-separated table reference list. table from one or more other tables given in a comma-separated
table reference list.
<synopsis> <synopsis>
FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_reference</replaceable> <optional>, ...</optional></optional> FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_reference</replaceable> <optional>, ...</optional></optional>
</synopsis> </synopsis>
...@@ -677,7 +678,8 @@ SELECT * ...@@ -677,7 +678,8 @@ SELECT *
</indexterm> </indexterm>
<para> <para>
The syntax of the <literal>WHERE</> clause is The syntax of the <xref linkend="sql-where"
endterm="sql-where-title"> clause is
<synopsis> <synopsis>
WHERE <replaceable>search_condition</replaceable> WHERE <replaceable>search_condition</replaceable>
</synopsis> </synopsis>
...@@ -783,13 +785,14 @@ SELECT <replaceable>select_list</replaceable> ...@@ -783,13 +785,14 @@ SELECT <replaceable>select_list</replaceable>
</synopsis> </synopsis>
<para> <para>
The <literal>GROUP BY</> clause is used to group together those rows in The <xref linkend="sql-groupby" endterm="sql-groupby-title"> is
a table that share the same values in all the columns listed. The used to group together those rows in a table that share the same
order in which the columns are listed does not matter. The values in all the columns listed. The order in which the columns
purpose is to reduce each group of rows sharing common values into are listed does not matter. The purpose is to reduce each group
one group row that is representative of all rows in the group. of rows sharing common values into one group row that is
This is done to eliminate redundancy in the output and/or compute representative of all rows in the group. This is done to
aggregates that apply to these groups. For instance: eliminate redundancy in the output and/or compute aggregates that
apply to these groups. For instance:
<screen> <screen>
<prompt>=></> <userinput>SELECT * FROM test1;</> <prompt>=></> <userinput>SELECT * FROM test1;</>
x | y x | y
...@@ -1058,7 +1061,7 @@ SELECT a AS value, b + c AS sum FROM ... ...@@ -1058,7 +1061,7 @@ SELECT a AS value, b + c AS sum FROM ...
<synopsis> <synopsis>
SELECT DISTINCT <replaceable>select_list</replaceable> ... SELECT DISTINCT <replaceable>select_list</replaceable> ...
</synopsis> </synopsis>
(Instead of <literal>DISTINCT</> the word <literal>ALL</literal> (Instead of <literal>DISTINCT</> the key word <literal>ALL</literal>
can be used to select the default behavior of retaining all rows.) can be used to select the default behavior of retaining all rows.)
</para> </para>
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.74 2003/12/14 00:15:03 neilc Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.75 2004/03/03 22:22:24 neilc Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -174,7 +174,8 @@ where <replaceable class="parameter">from_item</replaceable> can be one of: ...@@ -174,7 +174,8 @@ where <replaceable class="parameter">from_item</replaceable> can be one of:
</para> </para>
<para> <para>
<literal>FROM</literal>-clause elements can contain: The <literal>FROM</literal> clause can contain the following
elements:
<variablelist> <variablelist>
<varlistentry> <varlistentry>
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.27 2003/11/29 19:51:39 pgsql Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.28 2004/03/03 22:22:24 neilc Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -32,8 +32,8 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea ...@@ -32,8 +32,8 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
<para> <para>
<command>UPDATE</command> changes the values of the specified <command>UPDATE</command> changes the values of the specified
columns in all rows that satisfy the condition. Only the columns to columns in all rows that satisfy the condition. Only the columns to
be modified need be mentioned in the statement; columns not explicitly be modified need be mentioned in the <literal>SET</literal> clause;
<literal>SET</> retain their previous values. columns not explicitly modified retain their previous values.
</para> </para>
<para> <para>
...@@ -43,6 +43,14 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea ...@@ -43,6 +43,14 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
clause. clause.
</para> </para>
<para>
There are two ways to modify a table using information contained in
other tables in the database: using sub-selects, or specifying
additional tables in the <literal>FROM</literal> clause. Which
technique is more appropriate depends on the specific
circumstances.
</para>
<para> <para>
You must have the <literal>UPDATE</literal> privilege on the table You must have the <literal>UPDATE</literal> privilege on the table
to update it, as well as the <literal>SELECT</literal> to update it, as well as the <literal>SELECT</literal>
...@@ -99,7 +107,12 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea ...@@ -99,7 +107,12 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
<listitem> <listitem>
<para> <para>
A list of table expressions, allowing columns from other tables A list of table expressions, allowing columns from other tables
to appear in the <literal>WHERE</> condition and the update expressions. to appear in the <literal>WHERE</> condition and the update
expressions. This is similar to the list of tables that can be
specified in the <xref linkend="sql-from"
endterm="sql-from-title"> of a <command>SELECT</command>
statement; for example, an alias for the table name can be
specified.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -139,7 +152,7 @@ UPDATE <replaceable class="parameter">count</replaceable> ...@@ -139,7 +152,7 @@ UPDATE <replaceable class="parameter">count</replaceable>
<para> <para>
Change the word <literal>Drama</> to <literal>Dramatic</> in the Change the word <literal>Drama</> to <literal>Dramatic</> in the
column <structfield>kind</> of the table <literal>films</literal>: column <structfield>kind</> of the table <structname>films</structname>:
<programlisting> <programlisting>
UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama'; UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';
...@@ -148,7 +161,7 @@ UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama'; ...@@ -148,7 +161,7 @@ UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';
<para> <para>
Adjust temperature entries and reset precipitation to its default Adjust temperature entries and reset precipitation to its default
value in one row of the table <literal>weather</literal>: value in one row of the table <structname>weather</structname>:
<programlisting> <programlisting>
UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT
...@@ -156,13 +169,30 @@ UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT ...@@ -156,13 +169,30 @@ UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT
</programlisting> </programlisting>
</para> </para>
<para>
Increment the sales count of the salesperson who manages the
account for Acme Corporation, using the <literal>FROM</literal>
clause syntax:
<programlisting>
UPDATE employees SET sales_count = sales_count + 1 FROM accounts
WHERE accounts.name = 'Acme Corporation'
AND employees.id = accounts.sales_person;
</programlisting>
Perform the same operation, using a sub-select in the
<literal>WHERE</literal> clause:
<programlisting>
UPDATE employees SET sales_count = sales_count + 1 WHERE id =
(SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
</programlisting>
</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
<title>Compatibility</title> <title>Compatibility</title>
<para> <para>
This command conforms to the SQL standard. The This command conforms to the <acronym>SQL</acronym> standard. The
<literal>FROM</literal> clause is a <literal>FROM</literal> clause is a
<productname>PostgreSQL</productname> extension. <productname>PostgreSQL</productname> extension.
</para> </para>
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.34 2004/01/22 19:50:21 neilc Exp $ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.35 2004/03/03 22:22:24 neilc Exp $
--> -->
<chapter id="triggers"> <chapter id="triggers">
...@@ -449,9 +449,9 @@ typedef struct Trigger ...@@ -449,9 +449,9 @@ typedef struct Trigger
<para> <para>
The function <function>trigf</> reports the number of rows in the The function <function>trigf</> reports the number of rows in the
table <literal>ttest</> and skips the actual operation if the table <structname>ttest</> and skips the actual operation if the
command attempts to insert a null value into the column command attempts to insert a null value into the column
<literal>x</>. (So the trigger acts as a not-null constraint but <structfield>x</>. (So the trigger acts as a not-null constraint but
doesn't abort the transaction.) doesn't abort the transaction.)
</para> </para>
......
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