1
1
<!--
2
- $PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.88 2005/07/14 06:17:36 neilc Exp $
2
+ $PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.89 2005/08/01 20:31:04 tgl Exp $
3
3
PostgreSQL documentation
4
4
-->
5
5
@@ -30,7 +30,7 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="parameter">expression</replac
30
30
[ ORDER BY <replaceable class="parameter">expression</replaceable> [ ASC | DESC | USING <replaceable class="parameter">operator</replaceable> ] [, ...] ]
31
31
[ LIMIT { <replaceable class="parameter">count</replaceable> | ALL } ]
32
32
[ OFFSET <replaceable class="parameter">start</replaceable> ]
33
- [ FOR { UPDATE | SHARE } [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] ]
33
+ [ FOR { UPDATE | SHARE } [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ][ NOWAIT ] ]
34
34
35
35
where <replaceable class="parameter">from_item</replaceable> can be one of:
36
36
@@ -151,7 +151,7 @@ where <replaceable class="parameter">from_item</replaceable> can be one of:
151
151
</listitem>
152
152
</orderedlist>
153
153
</para>
154
-
154
+
155
155
<para>
156
156
You must have <literal>SELECT</literal> privilege on a table to
157
157
read its values. The use of <literal>FOR UPDATE</literal> or
@@ -506,7 +506,7 @@ HAVING <replaceable class="parameter">condition</replaceable>
506
506
<replaceable class="parameter">select_statement</replaceable> is
507
507
any <command>SELECT</command> statement without an <literal>ORDER
508
508
BY</>, <literal>LIMIT</>, <literal>FOR UPDATE</literal>, or
509
- <literal>FOR SHARE</literal> clause.
509
+ <literal>FOR SHARE</literal> clause.
510
510
(<literal>ORDER BY</> and <literal>LIMIT</> can be attached to a
511
511
subexpression if it is enclosed in parentheses. Without
512
512
parentheses, these clauses will be taken to apply to the result of
@@ -803,14 +803,14 @@ OFFSET <replaceable class="parameter">start</replaceable>
803
803
<para>
804
804
The <literal>FOR UPDATE</literal> clause has this form:
805
805
<synopsis>
806
- FOR UPDATE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ]
806
+ FOR UPDATE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ]
807
807
</synopsis>
808
808
</para>
809
809
810
810
<para>
811
811
The closely related <literal>FOR SHARE</literal> clause has this form:
812
812
<synopsis>
813
- FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ]
813
+ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ]
814
814
</synopsis>
815
815
</para>
816
816
@@ -831,6 +831,18 @@ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ]
831
831
linkend="mvcc">.
832
832
</para>
833
833
834
+ <para>
835
+ To prevent the operation from waiting for other transactions to commit,
836
+ use the <literal>NOWAIT</> option. <command>SELECT FOR UPDATE
837
+ NOWAIT</command> reports an error, rather than waiting, if a selected row
838
+ cannot be locked immediately. Note that <literal>NOWAIT</> applies only
839
+ to the row-level lock(s) — the required <literal>ROW SHARE</literal>
840
+ table-level lock is still taken in the ordinary way (see
841
+ <xref linkend="mvcc">). You can use the <literal>NOWAIT</> option of
842
+ <xref linkend="sql-lock" endterm="sql-lock-title">
843
+ if you need to acquire the table-level lock without waiting.
844
+ </para>
845
+
834
846
<para>
835
847
<literal>FOR SHARE</literal> behaves similarly, except that it
836
848
acquires a shared rather than exclusive lock on each retrieved
@@ -843,7 +855,8 @@ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ]
843
855
<para>
844
856
It is currently not allowed for a single <command>SELECT</command>
845
857
statement to include both <literal>FOR UPDATE</literal> and
846
- <literal>FOR SHARE</literal>.
858
+ <literal>FOR SHARE</literal>, nor can different parts of the statement use
859
+ both <literal>NOWAIT</> and normal waiting mode.
847
860
</para>
848
861
849
862
<para>
@@ -861,8 +874,8 @@ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ]
861
874
</para>
862
875
863
876
<para>
864
- It is possible for a <command>SELECT</> command using both
865
- <literal>LIMIT</literal> and <literal>FOR UPDATE/SHARE</literal>
877
+ It is possible for a <command>SELECT</> command using both
878
+ <literal>LIMIT</literal> and <literal>FOR UPDATE/SHARE</literal>
866
879
clauses to return fewer rows than specified by <literal>LIMIT</literal>.
867
880
This is because <literal>LIMIT</> is applied first. The command
868
881
selects the specified number of rows,