From 2a4fad1a0e43d6375ffa8eddb2d8dfa1ed36593f Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 1 Aug 2005 20:31:16 +0000 Subject: Add NOWAIT option to SELECT FOR UPDATE/SHARE. Original patch by Hans-Juergen Schoenig, revisions by Karel Zak and Tom Lane. --- doc/src/sgml/ref/select.sgml | 31 ++++++++++++++++++++++--------- doc/src/sgml/ref/select_into.sgml | 4 ++-- doc/src/sgml/sql.sgml | 4 ++-- 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'doc/src') 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 @@ @@ -30,7 +30,7 @@ SELECT [ ALL | DISTINCT [ ON ( expressionexpression [ ASC | DESC | USING operator ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start ] - [ FOR { UPDATE | SHARE } [ OF table_name [, ...] ] ] + [ FOR { UPDATE | SHARE } [ OF table_name [, ...] ] [ NOWAIT ] ] where from_item can be one of: @@ -151,7 +151,7 @@ where from_item can be one of: - + You must have SELECT privilege on a table to read its values. The use of FOR UPDATE or @@ -506,7 +506,7 @@ HAVING condition select_statement is any SELECT statement without an ORDER BY, LIMIT, FOR UPDATE, or - FOR SHARE clause. + FOR SHARE clause. (ORDER BY and 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 start The FOR UPDATE clause has this form: -FOR UPDATE [ OF table_name [, ...] ] +FOR UPDATE [ OF table_name [, ...] ] [ NOWAIT ] The closely related FOR SHARE clause has this form: -FOR SHARE [ OF table_name [, ...] ] +FOR SHARE [ OF table_name [, ...] ] [ NOWAIT ] @@ -831,6 +831,18 @@ FOR SHARE [ OF table_name [, ...] ] linkend="mvcc">. + + To prevent the operation from waiting for other transactions to commit, + use the NOWAIT option. SELECT FOR UPDATE + NOWAIT reports an error, rather than waiting, if a selected row + cannot be locked immediately. Note that NOWAIT applies only + to the row-level lock(s) — the required ROW SHARE + table-level lock is still taken in the ordinary way (see + ). You can use the NOWAIT option of + + if you need to acquire the table-level lock without waiting. + + FOR SHARE behaves similarly, except that it acquires a shared rather than exclusive lock on each retrieved @@ -843,7 +855,8 @@ FOR SHARE [ OF table_name [, ...] ] It is currently not allowed for a single SELECT statement to include both FOR UPDATE and - FOR SHARE. + FOR SHARE, nor can different parts of the statement use + both NOWAIT and normal waiting mode. @@ -861,8 +874,8 @@ FOR SHARE [ OF table_name [, ...] ] - It is possible for a SELECT command using both - LIMIT and FOR UPDATE/SHARE + It is possible for a SELECT command using both + LIMIT and FOR UPDATE/SHARE clauses to return fewer rows than specified by LIMIT. This is because LIMIT is applied first. The command selects the specified number of rows, diff --git a/doc/src/sgml/ref/select_into.sgml b/doc/src/sgml/ref/select_into.sgml index 7e6a4807b7b..d9967197b87 100644 --- a/doc/src/sgml/ref/select_into.sgml +++ b/doc/src/sgml/ref/select_into.sgml @@ -1,5 +1,5 @@ @@ -31,7 +31,7 @@ SELECT [ ALL | DISTINCT [ ON ( expressionexpression [ ASC | DESC | USING operator ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start ] - [ FOR { UPDATE | SHARE } [ OF tablename [, ...] ] ] + [ FOR { UPDATE | SHARE } [ OF table_name [, ...] ] [ NOWAIT ] ] diff --git a/doc/src/sgml/sql.sgml b/doc/src/sgml/sql.sgml index 070ba7080ce..1bd6c3cff9d 100644 --- a/doc/src/sgml/sql.sgml +++ b/doc/src/sgml/sql.sgml @@ -1,5 +1,5 @@ @@ -865,7 +865,7 @@ SELECT [ ALL | DISTINCT [ ON ( expressionexpression [ ASC | DESC | USING operator ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start ] - [ FOR { UPDATE | SHARE } [ OF class_name [, ...] ] ] + [ FOR { UPDATE | SHARE } [ OF table_name [, ...] ] [ NOWAIT ] ] -- cgit v1.2.3