11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/query.sgml,v 1.20 2001/11/08 23:34:33 petere Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/query.sgml,v 1.21 2001/11/19 05:37:53 tgl Exp $
33-->
44
55 <chapter id="tutorial-sql">
@@ -26,7 +26,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/query.sgml,v 1.20 2001/11/08 23:34:33 peter
2626 </para>
2727
2828 <para>
29- Examples in this manual can also be found in source distribution
29+ Examples in this manual can also be found in the
30+ <productname>PostgreSQL</productname> source distribution
3031 in the directory <filename>src/tutorial/</filename>. Refer to the
3132 <filename>README</filename> file in that directory for how to use
3233 them. To start the tutorial, do the following:
@@ -42,7 +43,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/query.sgml,v 1.20 2001/11/08 23:34:33 peter
4243</screen>
4344
4445 The <literal>\i</literal> command reads in commands from the
45- specifiedfiles . The <literal>-s</literal> option puts you in
46+ specifiedfile . The <literal>-s</literal> option puts you in
4647 single step mode which pauses before sending a query to the
4748 server. The commands used in this section are in the file
4849 <filename>basics.sql</filename>.
@@ -126,7 +127,7 @@ CREATE TABLE weather (
126127 differently than above, or even all on one line. Two dashes
127128 (<quote><literal>--</literal></quote>) introduce comments.
128129 Whatever follows them is ignored up to the end of the line. SQL
129- isalso case insensitive about key words and identifiers, except
130+ is case insensitive about key words and identifiers, except
130131 when identifiers are double-quoted to preserve the case (not done
131132 above).
132133 </para>
@@ -148,7 +149,7 @@ CREATE TABLE weather (
148149 precision</type>, <type>char(<replaceable>N</>)</type>,
149150 <type>varchar(<replaceable>N</>)</type>, <type>date</type>,
150151 <type>time</type>, <type>timestamp</type>, and
151- <type>interval</type> as well as other types of general utility
152+ <type>interval</type>, as well as other types of general utility
152153 and a rich set of geometric types.
153154 <productname>PostgreSQL</productname> can be customized with an
154155 arbitrary number of user-defined data types. Consequently, type
@@ -165,7 +166,7 @@ CREATE TABLE cities (
165166 location point
166167);
167168</programlisting>
168- The <type>point</type> type issuch a
169+ The <type>point</type> type isan example of a
169170 <productname>PostgreSQL</productname>-specific data type.
170171 </para>
171172
@@ -221,7 +222,7 @@ INSERT INTO cities VALUES ('San Francisco', '(-194.0, 53.0)');
221222INSERT INTO weather (city, temp_lo, temp_hi, prcp, date)
222223 VALUES ('San Francisco', 43, 57, 0.0, '1994-11-29');
223224</programlisting>
224- You canalso list the columns in a different order if you wish or
225+ You can list the columns in a different order if you wish or
225226 even omit some columns, e.g., unknown precipitation:
226227<programlisting>
227228INSERT INTO weather (date, city, temp_hi, temp_lo)
@@ -279,7 +280,7 @@ COPY weather FROM '/home/user/weather.txt';
279280<programlisting>
280281SELECT * FROM weather;
281282</programlisting>
282- (where <literal>*</literal> means <quote>all columns</quote>) and
283+ (here <literal>*</literal> means <quote>all columns</quote>) and
283284 the output should be:
284285<screen>
285286 city | temp_lo | temp_hi | prcp | date
@@ -373,9 +374,9 @@ SELECT DISTINCT city
373374 of the same or different tables at one time is called a
374375 <firstterm>join</firstterm> query. As an example, say you wish to
375376 list all the weather records together with the location of the
376- associated city.In effect , we need to compare the city column of
377+ associated city.To do that , we need to compare the city column of
377378 each row of the weather table with the name column of all rows in
378- the cities table.
379+ the cities table, and select the pairs of rows where these values match .
379380 <note>
380381 <para>
381382 This is only a conceptual model. The actual join may
@@ -409,7 +410,7 @@ SELECT *
409410 There is no result row for the city of Hayward. This is
410411 because there is no matching entry in the
411412 <classname>cities</classname> table for Hayward, so the join
412- cannot process the rows in the weather table. We will see
413+ ignores the unmatched rows in the weather table. We will see
413414 shortly how this can be fixed.
414415 </para>
415416 </listitem>
@@ -478,7 +479,7 @@ SELECT *
478479 found we want some <quote>empty values</quote> to be substituted
479480 for the <classname>cities</classname> table's columns. This kind
480481 of query is called an <firstterm>outer join</firstterm>. (The
481- joins we have seento far are inner joins.) The command looks
482+ joins we have seenso far are inner joins.) The command looks
482483 like this:
483484
484485<programlisting>
@@ -493,12 +494,13 @@ SELECT *
493494(3 rows)
494495</programlisting>
495496
496- In particular, this query is a <firstterm>left outer
497+ This query is called a <firstterm>left outer
497498 join</firstterm> because the table mentioned on the left of the
498499 join operator will have each of its rows in the output at least
499500 once, whereas the table on the right will only have those rows
500- output that match some row of the left table, and will have empty
501- values substituted appropriately.
501+ output that match some row of the left table. When outputting a
502+ left-table row for which there is no right-table match, empty (NULL)
503+ values are substituted for the right-table columns.
502504 </para>
503505
504506 <formalpara>
@@ -605,7 +607,11 @@ SELECT city FROM weather WHERE temp_lo = max(temp_lo); <lineannotation>WRONG
605607
606608 but this will not work since the aggregate
607609 <function>max</function> cannot be used in the
608- <literal>WHERE</literal> clause. However, as is often the case
610+ <literal>WHERE</literal> clause. (This restriction exists because
611+ the <literal>WHERE</literal> clause determines the rows that will
612+ go into the aggregation stage; so it has to be evaluated before
613+ aggregate functions are computed.)
614+ However, as is often the case
609615 the query can be restated to accomplish the intended result; here
610616 by using a <firstterm>subquery</firstterm>:
611617
@@ -697,7 +703,7 @@ SELECT city, max(temp_lo)
697703 </para>
698704
699705 <para>
700- Note that we can apply the city name restriction in
706+ Observe that we can apply the city name restriction in
701707 <literal>WHERE</literal>, since it needs no aggregate. This is
702708 more efficient than adding the restriction to <literal>HAVING</literal>,
703709 because we avoid doing the grouping and aggregate calculations
@@ -718,7 +724,7 @@ SELECT city, max(temp_lo)
718724 <command>UPDATE</command> command.
719725 Suppose you discover the temperature readings are
720726 all off by 2 degrees as of November 28, you may update the
721- data asfollow :
727+ data asfollows :
722728
723729<programlisting>
724730UPDATE weather
@@ -758,7 +764,7 @@ SELECT * FROM weather;
758764DELETE FROM weather WHERE city = 'Hayward';
759765</programlisting>
760766
761- All weatherrecording belonging to Hayward are removed.
767+ All weatherrecords belonging to Hayward are removed.
762768
763769<programlisting>
764770SELECT * FROM weather;
@@ -779,10 +785,10 @@ SELECT * FROM weather;
779785DELETE FROM <replaceable>tablename</replaceable>;
780786</synopsis>
781787
782- Without a qualification, <command>DELETE</command> will simply
783- remove all rows from the given table, leaving it
788+ Without a qualification, <command>DELETE</command> will
789+ remove<emphasis> all</> rows from the given table, leaving it
784790 empty. The system will not request confirmation before
785- doing this.
791+ doing this!
786792 </para>
787793 </sect1>
788794