Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XObQU-0001hw-Dq for pgsql-bugs@arkaria.postgresql.org; Mon, 01 Sep 2014 23:54:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XObQT-0003zd-T2 for pgsql-bugs@arkaria.postgresql.org; Mon, 01 Sep 2014 23:54:21 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XObQS-0003xK-LB for pgsql-bugs@postgresql.org; Mon, 01 Sep 2014 23:54:20 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XObQP-0002Bu-CU for pgsql-bugs@postgresql.org; Mon, 01 Sep 2014 23:54:18 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1XObQN-0000lo-Sa for pgsql-bugs@postgresql.org; Mon, 01 Sep 2014 16:54:15 -0700 Date: Mon, 1 Sep 2014 16:54:15 -0700 (PDT) From: David G Johnston To: pgsql-bugs@postgresql.org Message-ID: <1409615655879-5817259.post@n5.nabble.com> In-Reply-To: <1409606414605-5817249.post@n5.nabble.com> References: <20140901154149.2921.14246@wrigleys.postgresql.org> <17622.1409604522@sss.pgh.pa.us> <1409606414605-5817249.post@n5.nabble.com> Subject: Re: BUG #11325: Documentation Bug / RFE MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org David G Johnston wrote > > Tom Lane-2 wrote >> thomas@ >> writes: >>> Two suggestions for "PostgreSQL 9.3.5 Documentation" (which is excellent >>> in >>> general, by the way :-) >> >>> 1) "Finally, NATURAL is a shorthand form of USING: it forms a USING list >>> consisting of all column >>> names that appear in both input tables." >>> Please clarify: All column names that appear in both input tables >>> (regardless of the SELECT clause), or all column names /listed in the >>> SELECT >>> clause/ that appear in both input tables? >> >> "All column names that appear in both input tables" seems perfectly >> clear to me. Where would you get the idea that it had something to >> do with the SELECT list? >> >>> 2) "with the exception that if ON is used there will be two columns a, >>> b, >>> and c in the result" >>> Hard to understand. Suggestion: >>> "if ON is used, each column a, b, and c will appear twice in the >>> result." >> >> Yeah, that's fair, though perhaps it would be better as "each of the >> columns a, b, and c will appear twice in the result". > Agree on both counts. > > Though the entire "Thus, USING (a,b,c) ..." seems superfluous given the > subsequent example section. And given the 'furthermore' aspect of this it > isn't really "shorthand" for ON but it's own unique mechanic and syntax. > > A comment in its own paragraph to the effect: > > SELECT * output - > ON - all columns from T1 followed by all columns from T2 > USING - all join columns, one copy each and in the listed order, followed > by non-join columns in T1 followed by non-join columns in T2 > > could be added while removing the "thus" paragraph in USING; as well as > the concept of shorthand. > > David J. Usage note for USING/NATURAL added as well. diff --git a/doc/src/sgml/queries.sgml b/doc/src/sgml/queries.sgml index 9bf3136..c53c2b0 100644 --- a/doc/src/sgml/queries.sgml +++ b/doc/src/sgml/queries.sgml @@ -245,25 +245,38 @@ FROM table_reference , table_r condition: it takes a Boolean value expression of the same kind as is used in a WHERE clause. A pair of rows from T1 and T2 match if the - ON expression evaluates to true for them. + ON expression evaluates to true. - USING is a shorthand notation: it takes a - comma-separated list of column names, which the joined tables - must have in common, and forms a join condition specifying - equality of each of these pairs of columns. Furthermore, the - output of JOIN USING has one column for each of - the equated pairs of input columns, followed by the - remaining columns from each table. Thus, USING (a, b, - c) is equivalent to ON (t1.a = t2.a AND - t1.b = t2.b AND t1.c = t2.c) with the exception that - if ON is used there will be two columns - a, b, and c in the result, - whereas with USING there will be only one of each - (and they will appear first if SELECT * is used). + The USING clause allows you to take advantage of + the specific situation where both sides of the join use the + same name for the joining columns. It takes a + comma-separated list of the shared column names + and forms a join using the equals operator. Furthermore, the + output of JOIN USING has one column for each of the + listed columns, followed by the remaining columns from each table. + The output column difference between ON and USING when invoking SELECT * is: + + + + ON - all columns from T1 followed by all columns from T2 + + + + + USING - all join columns, one copy each and in the listed order, followed by non-join columns in T1 followed by non-join columns in T2 + + + + + Examples provided below + + + + join @@ -282,6 +295,16 @@ FROM table_reference , table_r + Usage Note: + USING is reasonably safe from column changes + in the joined relations since only the specific columns mentioned + are considered. NATURAL is considerably more problematic + if you are referring to relations only by name (views and tables) + since any schema changes to either relation that cause a new matching + column name to be present will cause the join to consider that new column. + + + The possible types of qualified join are: -- View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-11325-Documentation-Bug-RFE-tp5817245p5817259.html Sent from the PostgreSQL - bugs mailing list archive at Nabble.com. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs