Skip to content

Commit 3785d8e

Browse files
doc: Make UPDATE FROM examples consistent
The original first half of the example used an employees table and an accounts.sales_person foreign key column, while the second half (added in commit 8f889b1) used a salesmen table and accounts.sales_id for the foreign key. This makes everything use the original names. Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> Discussion: https://postgr.es/m/87o81vqjw0.fsf@wibble.ilmari.org
1 parent ebc8b7d commit 3785d8e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

doc/src/sgml/ref/update.sgml

+6-6
Original file line numberDiff line numberDiff line change
@@ -387,23 +387,23 @@ UPDATE employees SET sales_count = sales_count + 1 WHERE id =
387387

388388
<para>
389389
Update contact names in an accounts table to match the currently assigned
390-
salesmen:
390+
salespeople:
391391
<programlisting>
392392
UPDATE accounts SET (contact_first_name, contact_last_name) =
393-
(SELECT first_name, last_name FROM salesmen
394-
WHERE salesmen.id = accounts.sales_id);
393+
(SELECT first_name, last_name FROM employees
394+
WHERE employees.id = accounts.sales_person);
395395
</programlisting>
396396
A similar result could be accomplished with a join:
397397
<programlisting>
398398
UPDATE accounts SET contact_first_name = first_name,
399399
contact_last_name = last_name
400-
FROM salesmen WHERE salesmen.id = accounts.sales_id;
400+
FROM employees WHERE employees.id = accounts.sales_person;
401401
</programlisting>
402402
However, the second query may give unexpected results
403-
if <structname>salesmen</structname>.<structfield>id</structfield> is not a unique key, whereas
403+
if <structname>employees</structname>.<structfield>id</structfield> is not a unique key, whereas
404404
the first query is guaranteed to raise an error if there are multiple
405405
<structfield>id</structfield> matches. Also, if there is no match for a particular
406-
<structname>accounts</structname>.<structfield>sales_id</structfield> entry, the first query
406+
<structname>accounts</structname>.<structfield>sales_person</structfield> entry, the first query
407407
will set the corresponding name fields to NULL, whereas the second query
408408
will not update that row at all.
409409
</para>

0 commit comments

Comments
 (0)