Add a few more cross-references where appropriate, add more text about
authorNeil Conway
Wed, 3 Mar 2004 22:22:24 +0000 (22:22 +0000)
committerNeil Conway
Wed, 3 Mar 2004 22:22:24 +0000 (22:22 +0000)
the FROM clause and an example to the UPDATE reference page, and make
a few other SGML tweaks.

doc/src/sgml/queries.sgml
doc/src/sgml/ref/select.sgml
doc/src/sgml/ref/update.sgml
doc/src/sgml/trigger.sgml

index a3b0aa2d147d765b622e4378dbc59329d2518e17..185602c151ceb26f84d23ca03b64248934ddca51 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
 
  Queries
@@ -108,8 +108,9 @@ SELECT random();
    The <literal>FROM</literal> Clause
  
    
-    The FROM clause derives a table from one or more other
-    tables given in a comma-separated table reference list.
+    The  derives a
+    table from one or more other tables given in a comma-separated
+    table reference list.
 
 FROM table_reference table_reference , ...
 
@@ -677,7 +678,8 @@ SELECT *
    
 
    
-    The syntax of the WHERE clause is
+    The syntax of the 
+    endterm="sql-where-title"> clause is
 
 WHERE search_condition
 
@@ -783,13 +785,14 @@ SELECT select_list
 
 
    
-    The GROUP BY clause is used to group together those rows in
-    a table that share the same values in all the columns listed. The
-    order in which the columns are listed does not matter.  The
-    purpose is to reduce each group of rows sharing common values into
-    one group row that is representative of all rows in the group.
-    This is done to eliminate redundancy in the output and/or compute
-    aggregates that apply to these groups.  For instance:
+    The  is
+    used to group together those rows in a table that share the same
+    values in all the columns listed. The order in which the columns
+    are listed does not matter.  The purpose is to reduce each group
+    of rows sharing common values into one group row that is
+    representative of all rows in the group.  This is done to
+    eliminate redundancy in the output and/or compute aggregates that
+    apply to these groups.  For instance:
 
 => SELECT * FROM test1;
  x | y
@@ -1058,7 +1061,7 @@ SELECT a AS value, b + c AS sum FROM ...
 
 SELECT DISTINCT select_list ...
 
-    (Instead of DISTINCT the word ALL
+    (Instead of DISTINCT the key word ALL
     can be used to select the default behavior of retaining all rows.)
    
 
index c765329df11fde15c2f4419cc6a62d70a572a3d3..63a85b2a00df4ba9519bd52e6567f10e8f515d02 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -174,7 +174,8 @@ where from_item can be one of:
    
 
    
-    FROM-clause elements can contain:
+    The FROM clause can contain the following
+    elements:
 
     
      
@@ -289,16 +290,16 @@ where from_item can be one of:
         A JOIN clause combines two
         FROM items.  Use parentheses if necessary to
         determine the order of nesting.  In the absence of parentheses,
-   JOINs nest left-to-right.  In any case
-   JOIN binds more tightly than the commas
-   separating FROM items.
+        JOINs nest left-to-right.  In any case
+        JOIN binds more tightly than the commas
+        separating FROM items.
        
 
        
         CROSS JOIN and INNER JOIN
         produce a simple Cartesian product, the same result as you get from
         listing the two items at the top level of FROM,
-   but restricted by the join condition (if any).
+        but restricted by the join condition (if any).
         CROSS JOIN is equivalent to INNER JOIN ON
         (TRUE), that is, no rows are removed by qualification.
         These join types are just a notational convenience, since they
@@ -647,7 +648,7 @@ SELECT name FROM distributors ORDER BY code;
     INTERSECT, or EXCEPT clause may only
     specify an output column name or number, not an expression.
    
-    
+
    
     If an ORDER BY expression is a simple name that
     matches both a result column name and an input column name,
index e95278af288c7cd47817af5338835b1f8c424cbd..6a6cf99137314ec811c37306b94867610c3656a6 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -32,8 +32,8 @@ UPDATE [ ONLY ] table SET 
   
    UPDATE changes the values of the specified
    columns in all rows that satisfy the condition. Only the columns to
-   be modified need be mentioned in the statement; columns not explicitly
-   SET retain their previous values.
+   be modified need be mentioned in the SET clause;
+   columns not explicitly modified retain their previous values.
   
 
   
@@ -43,6 +43,14 @@ UPDATE [ ONLY ] table SET 
    clause.
   
 
+  
+   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 FROM clause. Which
+   technique is more appropriate depends on the specific
+   circumstances.
+  
+
   
    You must have the UPDATE privilege on the table
    to update it, as well as the SELECT
@@ -99,7 +107,12 @@ UPDATE [ ONLY ] table SET 
     
      
       A list of table expressions, allowing columns from other tables
-      to appear in the WHERE condition and the update expressions.
+      to appear in the WHERE condition and the update
+      expressions. This is similar to the list of tables that can be
+      specified in the 
+      endterm="sql-from-title"> of a SELECT
+      statement; for example, an alias for the table name can be
+      specified.
      
     
    
@@ -139,7 +152,7 @@ UPDATE count
 
   
    Change the word Drama to Dramatic in the
-   column kind of the table <literal>films>:
+   column kind of the table <structname>films>:
 
 
 UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';
@@ -148,7 +161,7 @@ UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';
 
   
    Adjust temperature entries and reset precipitation to its default
-   value in one row of the table <literal>weather>:
+   value in one row of the table <structname>weather>:
 
 
 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
 
   
 
+  
+   Increment the sales count of the salesperson who manages the
+   account for Acme Corporation, using the FROM
+   clause syntax:
+
+UPDATE employees SET sales_count = sales_count + 1 FROM accounts
+  WHERE accounts.name = 'Acme Corporation'
+  AND employees.id = accounts.sales_person;
+
+
+   Perform the same operation, using a sub-select in the
+   WHERE clause:
+
+UPDATE employees SET sales_count = sales_count + 1 WHERE id =
+  (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
+
+  
  
 
  
   Compatibility
 
   
-   This command conforms to the SQL standard.  The
+   This command conforms to the SQL standard.  The
    FROM clause is a
    PostgreSQL extension.
   
index 79a438da8fb40235473099b170186829c75b91bf..a8ee6c7d9515926ceeba37d2b6d6347ce01164b4 100644 (file)
@@ -1,5 +1,5 @@
 
 
  
@@ -449,9 +449,9 @@ typedef struct Trigger
 
    
     The 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
-    <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.)