Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b548cde

Browse files
committed
Some more small improvements in response to 7.4 interactive docs comments.
1 parent 8afe005 commit b548cde

File tree

6 files changed

+112
-24
lines changed

6 files changed

+112
-24
lines changed

doc/src/sgml/ref/create_table_as.sgml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.28 2005/01/05 14:22:39 petere Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.29 2005/01/09 05:57:45 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -157,6 +157,20 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
157157
</para>
158158
</refsect1>
159159

160+
<refsect1>
161+
<title>Examples</title>
162+
163+
<para>
164+
Create a new table <literal>films_recent</literal> consisting of only
165+
recent entries from the table <literal>films</literal>:
166+
167+
<programlisting>
168+
CREATE TABLE films_recent AS
169+
SELECT * FROM films WHERE date_prod &gt;= '2002-01-01';
170+
</programlisting>
171+
</para>
172+
</refsect1>
173+
160174
<refsect1>
161175
<title>Compatibility</title>
162176

doc/src/sgml/ref/delete.sgml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/delete.sgml,v 1.21 2005/01/04 00:39:53 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/delete.sgml,v 1.22 2005/01/09 05:57:45 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -100,6 +100,33 @@ DELETE <replaceable class="parameter">count</replaceable>
100100
</para>
101101
</refsect1>
102102

103+
<refsect1>
104+
<title>Notes</title>
105+
106+
<para>
107+
<productname>PostgreSQL</productname> lets you reference columns of
108+
other tables in the <literal>WHERE</> condition. For example, to
109+
delete all films produced by a given producer, one might do
110+
<programlisting>
111+
DELETE FROM films
112+
WHERE producer_id = producers.id AND producers.name = 'foo';
113+
</programlisting>
114+
What is essentially happening here is a join between <structname>films</>
115+
and <structname>producers</>, with all successfully joined
116+
<structname>films</> rows being marked for deletion.
117+
This syntax is not standard. A more standard way to do it is
118+
<programlisting>
119+
DELETE FROM films
120+
WHERE producer_id IN (SELECT id FROM producers WHERE name = 'foo');
121+
</programlisting>
122+
In some cases the join style is easier to write or faster to
123+
execute than the sub-select style. One objection to the join style
124+
is that there is no explicit list of what tables are being used,
125+
which makes the style somewhat error-prone; also it cannot handle
126+
self-joins.
127+
</para>
128+
</refsect1>
129+
103130
<refsect1>
104131
<title>Examples</title>
105132

@@ -122,7 +149,9 @@ DELETE FROM films;
122149
<title>Compatibility</title>
123150

124151
<para>
125-
This command conforms to the SQL standard.
152+
This command conforms to the SQL standard, except that the ability to
153+
reference other tables in the <literal>WHERE</> clause is a
154+
<productname>PostgreSQL</productname> extension.
126155
</para>
127156
</refsect1>
128157
</refentry>

doc/src/sgml/ref/drop_group.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_group.sgml,v 1.9 2005/01/04 00:39:53 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_group.sgml,v 1.10 2005/01/09 05:57:45 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -29,7 +29,7 @@ DROP GROUP <replaceable class="PARAMETER">name</replaceable>
2929

3030
<para>
3131
<command>DROP GROUP</command> removes the specified group. The
32-
users in the group are not deleted.
32+
users in the group are not removed.
3333
</para>
3434
</refsect1>
3535

doc/src/sgml/ref/insert.sgml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/insert.sgml,v 1.28 2005/01/04 00:39:53 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/insert.sgml,v 1.29 2005/01/09 05:57:45 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -162,7 +162,7 @@ INSERT INTO films VALUES
162162
</para>
163163

164164
<para>
165-
In this second example, the <literal>len</literal> column is
165+
In this example, the <literal>len</literal> column is
166166
omitted and therefore it will have the default value:
167167

168168
<programlisting>
@@ -172,7 +172,7 @@ INSERT INTO films (code, title, did, date_prod, kind)
172172
</para>
173173

174174
<para>
175-
The third example uses the <literal>DEFAULT</literal> clause for
175+
This example uses the <literal>DEFAULT</literal> clause for
176176
the date columns rather than specifying a value:
177177

178178
<programlisting>
@@ -184,11 +184,20 @@ INSERT INTO films (code, title, did, date_prod, kind)
184184
</para>
185185

186186
<para>
187-
This example inserts several rows into table
188-
<literal>films</literal> from table <literal>tmp</literal>:
187+
To insert a row consisting entirely of default values:
189188

190189
<programlisting>
191-
INSERT INTO films SELECT * FROM tmp;
190+
INSERT INTO films DEFAULT VALUES;
191+
</programlisting>
192+
</para>
193+
194+
<para>
195+
This example inserts some rows into table
196+
<literal>films</literal> from a table <literal>tmp_films</literal>
197+
with the same column layout as <literal>films</literal>:
198+
199+
<programlisting>
200+
INSERT INTO films SELECT * FROM tmp_films WHERE date_prod &lt; '2004-05-07';
192201
</programlisting>
193202
</para>
194203

doc/src/sgml/ref/select_into.sgml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/select_into.sgml,v 1.32 2005/01/04 03:58:16 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/select_into.sgml,v 1.33 2005/01/09 05:57:45 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -105,6 +105,19 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac
105105
</para>
106106
</refsect1>
107107

108+
<refsect1>
109+
<title>Examples</title>
110+
111+
<para>
112+
Create a new table <literal>films_recent</literal> consisting of only
113+
recent entries from the table <literal>films</literal>:
114+
115+
<programlisting>
116+
SELECT * INTO films_recent FROM films WHERE date_prod &gt;= '2002-01-01';
117+
</programlisting>
118+
</para>
119+
</refsect1>
120+
108121
<refsect1>
109122
<title>Compatibility</title>
110123

@@ -120,6 +133,14 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac
120133
new code.
121134
</para>
122135
</refsect1>
136+
137+
<refsect1>
138+
<title>See Also</title>
139+
140+
<simplelist type="inline">
141+
<member><xref linkend="sql-createtableas" endterm="sql-createtableas-title"></member>
142+
</simplelist>
143+
</refsect1>
123144
</refentry>
124145

125146
<!-- Keep this comment at the end of the file

doc/src/sgml/ref/update.sgml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.31 2005/01/04 03:58:16 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.32 2005/01/09 05:57:45 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -114,8 +114,9 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
114114
expressions. This is similar to the list of tables that can be
115115
specified in the <xref linkend="sql-from"
116116
endterm="sql-from-title"> of a <command>SELECT</command>
117-
statement; for example, an alias for the table name can be
118-
specified.
117+
statement. Note that the target table must not appear in the
118+
<replaceable>fromlist</>, unless you intend a self-join (in which
119+
case it must appear with an alias in the <replaceable>fromlist</>).
119120
</para>
120121
</listitem>
121122
</varlistentry>
@@ -154,10 +155,13 @@ UPDATE <replaceable class="parameter">count</replaceable>
154155
<title>Notes</title>
155156

156157
<para>
157-
When joining the target table to other tables using a <replaceable
158-
class="PARAMETER">fromlist</replaceable>, be careful that the join
158+
When a <literal>FROM</> clause is present, what essentially happens
159+
is that the target table is joined to the tables mentioned in the
160+
<replaceable>fromlist</replaceable>, and each output row of the join
161+
represents an update operation for the target table. When using
162+
<literal>FROM</> you should ensure that the join
159163
produces at most one output row for each row to be modified. In
160-
other words, a target row mustn't join to more than one row from
164+
other words, a target row shouldn't join to more than one row from
161165
the other table(s). If it does, then only one of the join rows
162166
will be used to update the target row, but which one will be used
163167
is not readily predictable.
@@ -210,15 +214,18 @@ UPDATE employees SET sales_count = sales_count + 1 WHERE id =
210214
</programlisting>
211215

212216
Attempt to insert a new stock item along with the quantity of stock. If
213-
the item exists, update the stock count of the existing item. To do this,
214-
use savepoints.
217+
the item already exists, instead update the stock count of the existing
218+
item. To do this without failing the entire transaction, use savepoints.
215219
<programlisting>
216220
BEGIN;
221+
-- other operations
217222
SAVEPOINT sp1;
218223
INSERT INTO wines VALUES('Chateau Lafite 2003', '24');
219-
-- Check for unique violation on name
224+
-- Assume the above fails because of a unique key violation,
225+
-- so now we issue these commands:
220226
ROLLBACK TO sp1;
221-
UPDATE wines SET stock = stock + 24 WHERE winename='Chateau Lafite 2003';
227+
UPDATE wines SET stock = stock + 24 WHERE winename = 'Chateau Lafite 2003';
228+
-- continue with other operations, and eventually
222229
COMMIT;
223230
</programlisting>
224231
</para>
@@ -228,10 +235,18 @@ COMMIT;
228235
<title>Compatibility</title>
229236

230237
<para>
231-
This command conforms to the <acronym>SQL</acronym> standard. The
232-
<literal>FROM</literal> clause is a
238+
This command conforms to the <acronym>SQL</acronym> standard, except
239+
that the <literal>FROM</literal> clause is a
233240
<productname>PostgreSQL</productname> extension.
234241
</para>
242+
243+
<para>
244+
Some other database systems offer a <literal>FROM</> option in which
245+
the target table is supposed to be listed again within <literal>FROM</>.
246+
That is not how <productname>PostgreSQL</productname> interprets
247+
<literal>FROM</>. Be careful when porting applications that use this
248+
extension.
249+
</para>
235250
</refsect1>
236251
</refentry>
237252

0 commit comments

Comments
 (0)