|
1 | 1 | <!--
|
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 $ |
3 | 3 | PostgreSQL documentation
|
4 | 4 | -->
|
5 | 5 |
|
@@ -368,13 +368,14 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
|
368 | 368 | </para>
|
369 | 369 |
|
370 | 370 | <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. |
373 | 373 | </para>
|
374 | 374 |
|
375 | 375 | <para>
|
376 | 376 | You must have SELECT privilege to a table to read its values
|
377 | 377 | (See the <command>GRANT</command>/<command>REVOKE</command> statements).
|
| 378 | + Use of FOR UPDATE requires UPDATE privilege as well. |
378 | 379 | </para>
|
379 | 380 |
|
380 | 381 | <refsect2 id="SQL-FROM">
|
@@ -859,19 +860,32 @@ SELECT name FROM distributors ORDER BY code;
|
859 | 860 | <para>
|
860 | 861 | FOR UPDATE causes the rows retrieved by the query to be locked as though
|
861 | 862 | 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>. |
863 | 871 | </para>
|
864 | 872 |
|
865 | 873 | <para>
|
866 | 874 | 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. |
868 | 877 | </para>
|
869 | 878 |
|
870 | 879 | <para>
|
871 | 880 | FOR UPDATE cannot be used in contexts where returned rows can't be clearly
|
872 | 881 | 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. |
875 | 889 | </para>
|
876 | 890 | </refsect2>
|
877 | 891 |
|
|
0 commit comments