diff options
Diffstat (limited to 'doc/src/sgml/ref/select.sgml')
-rw-r--r-- | doc/src/sgml/ref/select.sgml | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml index d29f8e48e0e..48a192d1b90 100644 --- a/doc/src/sgml/ref/select.sgml +++ b/doc/src/sgml/ref/select.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.88 2005/07/14 06:17:36 neilc Exp $ +$PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.89 2005/08/01 20:31:04 tgl Exp $ PostgreSQL documentation --> @@ -30,7 +30,7 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="parameter">expression</replac [ ORDER BY <replaceable class="parameter">expression</replaceable> [ ASC | DESC | USING <replaceable class="parameter">operator</replaceable> ] [, ...] ] [ LIMIT { <replaceable class="parameter">count</replaceable> | ALL } ] [ OFFSET <replaceable class="parameter">start</replaceable> ] - [ FOR { UPDATE | SHARE } [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] ] + [ FOR { UPDATE | SHARE } [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ] ] where <replaceable class="parameter">from_item</replaceable> can be one of: @@ -151,7 +151,7 @@ where <replaceable class="parameter">from_item</replaceable> can be one of: </listitem> </orderedlist> </para> - + <para> You must have <literal>SELECT</literal> privilege on a table to read its values. The use of <literal>FOR UPDATE</literal> or @@ -506,7 +506,7 @@ HAVING <replaceable class="parameter">condition</replaceable> <replaceable class="parameter">select_statement</replaceable> is any <command>SELECT</command> statement without an <literal>ORDER BY</>, <literal>LIMIT</>, <literal>FOR UPDATE</literal>, or - <literal>FOR SHARE</literal> clause. + <literal>FOR SHARE</literal> clause. (<literal>ORDER BY</> and <literal>LIMIT</> can be attached to a subexpression if it is enclosed in parentheses. Without parentheses, these clauses will be taken to apply to the result of @@ -803,14 +803,14 @@ OFFSET <replaceable class="parameter">start</replaceable> <para> The <literal>FOR UPDATE</literal> clause has this form: <synopsis> -FOR UPDATE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] +FOR UPDATE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ] </synopsis> </para> <para> The closely related <literal>FOR SHARE</literal> clause has this form: <synopsis> -FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] +FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ] </synopsis> </para> @@ -832,6 +832,18 @@ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] </para> <para> + To prevent the operation from waiting for other transactions to commit, + use the <literal>NOWAIT</> option. <command>SELECT FOR UPDATE + NOWAIT</command> reports an error, rather than waiting, if a selected row + cannot be locked immediately. Note that <literal>NOWAIT</> applies only + to the row-level lock(s) — the required <literal>ROW SHARE</literal> + table-level lock is still taken in the ordinary way (see + <xref linkend="mvcc">). You can use the <literal>NOWAIT</> option of + <xref linkend="sql-lock" endterm="sql-lock-title"> + if you need to acquire the table-level lock without waiting. + </para> + + <para> <literal>FOR SHARE</literal> behaves similarly, except that it acquires a shared rather than exclusive lock on each retrieved row. A shared lock blocks other transactions from performing @@ -843,7 +855,8 @@ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] <para> It is currently not allowed for a single <command>SELECT</command> statement to include both <literal>FOR UPDATE</literal> and - <literal>FOR SHARE</literal>. + <literal>FOR SHARE</literal>, nor can different parts of the statement use + both <literal>NOWAIT</> and normal waiting mode. </para> <para> @@ -861,8 +874,8 @@ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] </para> <para> - It is possible for a <command>SELECT</> command using both - <literal>LIMIT</literal> and <literal>FOR UPDATE/SHARE</literal> + It is possible for a <command>SELECT</> command using both + <literal>LIMIT</literal> and <literal>FOR UPDATE/SHARE</literal> clauses to return fewer rows than specified by <literal>LIMIT</literal>. This is because <literal>LIMIT</> is applied first. The command selects the specified number of rows, |