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

Commit fb9bc34

Browse files
committed
Improve discussion of FOR UPDATE.
1 parent f99e525 commit fb9bc34

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

doc/src/sgml/ref/select.sgml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.61 2002/09/21 18:32:54 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.62 2002/10/18 18:26:22 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -368,13 +368,14 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
368368
</para>
369369

370370
<para>
371-
The FOR UPDATE clause allows the SELECT statement to perform
372-
exclusive locking of selected rows.
371+
The FOR UPDATE clause causes the SELECT statement to lock the selected
372+
rows against concurrent updates.
373373
</para>
374374

375375
<para>
376376
You must have SELECT privilege to a table to read its values
377377
(See the <command>GRANT</command>/<command>REVOKE</command> statements).
378+
Use of FOR UPDATE requires UPDATE privilege as well.
378379
</para>
379380

380381
<refsect2 id="SQL-FROM">
@@ -859,19 +860,32 @@ SELECT name FROM distributors ORDER BY code;
859860
<para>
860861
FOR UPDATE causes the rows retrieved by the query to be locked as though
861862
for update. This prevents them from being modified or deleted by other
862-
transactions until the current transaction ends.
863+
transactions until the current transaction ends; that is, other
864+
transactions that attempt UPDATE, DELETE, or SELECT FOR UPDATE of these
865+
rows will be blocked until the current transaction ends. Also, if an
866+
UPDATE, DELETE, or SELECT FOR UPDATE from another transaction has already
867+
locked a selected row or rows, SELECT FOR UPDATE will wait for the other
868+
transaction to complete, and will then lock and return the updated row
869+
(or no row, if the row was deleted). For further discussion see the
870+
concurrency chapter of the <citetitle>User's Guide</citetitle>.
863871
</para>
864872

865873
<para>
866874
If specific tables are named in FOR UPDATE, then only rows coming from
867-
those tables are locked.
875+
those tables are locked; any other tables used in the SELECT are simply
876+
read as usual.
868877
</para>
869878

870879
<para>
871880
FOR UPDATE cannot be used in contexts where returned rows can't be clearly
872881
identified with individual table rows; for example it can't be used with
873-
aggregation. FOR UPDATE may also appear before LIMIT for portability with
874-
pre-7.3 applications.
882+
aggregation.
883+
</para>
884+
885+
<para>
886+
FOR UPDATE may appear before LIMIT for compatibility with
887+
pre-7.3 applications. However, it effectively executes after LIMIT,
888+
and so that is the recommended place to write it.
875889
</para>
876890
</refsect2>
877891

0 commit comments

Comments
 (0)