From 3785d8e98b741749d09f1cfe119ec04961ed07b2 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Tue, 29 Mar 2022 14:53:20 +0200 Subject: [PATCH] doc: Make UPDATE FROM examples consistent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 8f889b1083f) used a salesmen table and accounts.sales_id for the foreign key. This makes everything use the original names. Author: Dagfinn Ilmari Mannsåker Discussion: https://postgr.es/m/87o81vqjw0.fsf@wibble.ilmari.org --- doc/src/sgml/ref/update.sgml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/src/sgml/ref/update.sgml b/doc/src/sgml/ref/update.sgml index 3a0285df79..2ab24b0523 100644 --- a/doc/src/sgml/ref/update.sgml +++ b/doc/src/sgml/ref/update.sgml @@ -387,23 +387,23 @@ UPDATE employees SET sales_count = sales_count + 1 WHERE id = Update contact names in an accounts table to match the currently assigned - salesmen: + salespeople: UPDATE accounts SET (contact_first_name, contact_last_name) = - (SELECT first_name, last_name FROM salesmen - WHERE salesmen.id = accounts.sales_id); + (SELECT first_name, last_name FROM employees + WHERE employees.id = accounts.sales_person); A similar result could be accomplished with a join: UPDATE accounts SET contact_first_name = first_name, contact_last_name = last_name - FROM salesmen WHERE salesmen.id = accounts.sales_id; + FROM employees WHERE employees.id = accounts.sales_person; However, the second query may give unexpected results - if salesmen.id is not a unique key, whereas + if employees.id is not a unique key, whereas the first query is guaranteed to raise an error if there are multiple id matches. Also, if there is no match for a particular - accounts.sales_id entry, the first query + accounts.sales_person entry, the first query will set the corresponding name fields to NULL, whereas the second query will not update that row at all.