From 055fee7eb4dcc78e58672aef146334275e1cc40d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 31 Mar 2021 17:09:24 +0200 Subject: Allow an alias to be attached to a JOIN ... USING This allows something like SELECT ... FROM t1 JOIN t2 USING (a, b, c) AS x where x has the columns a, b, c and unlike a regular alias it does not hide the range variables of the tables being joined t1 and t2. Per SQL:2016 feature F404 "Range variable for common column names". Reviewed-by: Vik Fearing Reviewed-by: Tom Lane Discussion: https://www.postgresql.org/message-id/flat/454638cf-d563-ab76-a585-2564428062af@2ndquadrant.com --- doc/src/sgml/ref/select.sgml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml index 9c5cf50ef0c..fa676b1698d 100644 --- a/doc/src/sgml/ref/select.sgml +++ b/doc/src/sgml/ref/select.sgml @@ -59,7 +59,7 @@ SELECT [ ALL | DISTINCT [ ON ( expressionfunction_name ( [ argument [, ...] ] ) AS ( column_definition [, ...] ) [ LATERAL ] ROWS FROM( function_name ( [ argument [, ...] ] ) [ AS ( column_definition [, ...] ) ] [, ...] ) [ WITH ORDINALITY ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ] - from_item [ NATURAL ] join_type from_item [ ON join_condition | USING ( join_column [, ...] ) ] + from_item [ NATURAL ] join_type from_item [ ON join_condition | USING ( join_column [, ...] ) [ AS join_using_alias ] ] and grouping_element can be one of: @@ -676,7 +676,7 @@ TABLE [ ONLY ] table_name [ * ] - USING ( join_column [, ...] ) + USING ( join_column [, ...] ) [ AS join_using_alias ] A clause of the form USING ( a, b, ... ) is @@ -686,6 +686,18 @@ TABLE [ ONLY ] table_name [ * ] equivalent columns will be included in the join output, not both. + + + If a join_using_alias + name is specified, it provides a table alias for the join columns. + Only the join columns listed in the USING clause + are addressable by this name. Unlike a regular alias, this does not hide the names of + the joined tables from the rest of the query. Also unlike a regular + alias, you cannot write a + column alias list — the output names of the join columns are the + same as they appear in the USING list. + -- cgit v1.2.3