Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r475f-007P9w-Vx for pgsql-docs@arkaria.postgresql.org; Fri, 17 Nov 2023 22:13:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r475e-00GaaM-JH for pgsql-docs@arkaria.postgresql.org; Fri, 17 Nov 2023 22:13:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r475e-00GaaE-BN for pgsql-docs@lists.postgresql.org; Fri, 17 Nov 2023 22:13:30 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r475X-006y9T-Fd for pgsql-docs@lists.postgresql.org; Fri, 17 Nov 2023 22:13:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2023062407; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description; bh=FVS2bKXFnMPcZ8FkFyqXxWOzzZjrAaD6Ed+VMRbLqac=; b=VeZSM 74xA30rWGmsh75I1sQMAbOwQ+LdtCi8bLhUxFmvmeebk4cR+vMihlQZXarVEPEiGIDU3nFlHreXIG xhgvFDhD96Ws1DIXg3b4hFsg5Ol7oBrD4MW/TzJq+D/l3RZEHNK212LQkOn9e9TN87cjHyo8bvQMX ovLIwOCPWSAAqp//nBNe/TPEqbQjEKb4EG4WeyB1UxfTofvyxdZ1pJO3GqNkYcMMn7WIkUCSKMCrG rzRAVV4gv5LK3YW/dYGnDU/K+w5d+zuqH2i7bLNhbokJroHXVqKOjlzjAsXYDFJPIi4ZWfAF7Qg0v LZN3ZoYzl24g+f3M0Tdp5NVQyP4Iw==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1r475V-00BcZz-1e; Fri, 17 Nov 2023 17:13:21 -0500 Date: Fri, 17 Nov 2023 17:13:21 -0500 From: Bruce Momjian To: lists@humanleg.org.uk, pgsql-docs@lists.postgresql.org Subject: Re: SELECT ... FOR UPDATE OF clause documentation implies use of table_names rather than aliases Message-ID: References: <152483686904.19805.3369061025704720797@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Md4Te6NsgYp2LUUb" Content-Disposition: inline In-Reply-To: <152483686904.19805.3369061025704720797@wrigleys.postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Md4Te6NsgYp2LUUb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Apr 27, 2018 at 01:47:49PM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/9.5/static/sql-select.html > Description: > > In the SELECT statement page the argument type of the (FOR SHARE/UPDATE) OF > clause is listed to be a table_name. This is not *quite* accurate - it > should reference the *alias* assigned to the table if one was given. The > distinction is subtly important, as without this information the > documentation implies that the choice of rows to lock can only be done > per-table (i.e. that in a query mentioning the same table twice, *any* > tuples being pulled from that table would be given the same treatment). > > But in fact postgres supports specifying the locking behaviour per-alias, > which is a really powerful ability. And actually, trying to specify it by > actual "table name" where an alias has been assigned won't work either. I can confirm this report from 2018: CREATE TABLE test ( x INT ); SELECT * FROM test AS t1 JOIN test AS t2 ON (TRUE) FOR UPDATE OF t1; x | x ---+--- SELECT * FROM test AS t1 JOIN test AS t2 ON (TRUE) FOR UPDATE OF t2; x | x ---+--- The attached patch documents this. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you. --Md4Te6NsgYp2LUUb Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="alias.diff" diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml index 227ba1993b..ab3760057c 100644 --- a/doc/src/sgml/ref/select.sgml +++ b/doc/src/sgml/ref/select.sgml @@ -45,7 +45,7 @@ SELECT [ ALL | DISTINCT [ ON ( expressioncount | ALL } ] [ OFFSET start [ ROW | ROWS ] ] [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } { ONLY | WITH TIES } ] - [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT | SKIP LOCKED ] [...] ] + [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF { table_name | alias } [, ...] ] [ NOWAIT | SKIP LOCKED ] [...] ] where from_item can be one of: --Md4Te6NsgYp2LUUb--