From bcedd8f5fce0b69970cf0cee7bca560833d05869 Mon Sep 17 00:00:00 2001 From: Dean Rasheed Date: Wed, 20 Jul 2022 09:29:42 +0100 Subject: Make subquery aliases optional in the FROM clause. This allows aliases for sub-SELECTs and VALUES clauses in the FROM clause to be omitted. This is an extension of the SQL standard, supported by some other database systems, and so eases the transition from such systems, as well as removing the minor inconvenience caused by requiring these aliases. Patch by me, reviewed by Tom Lane. Discussion: https://postgr.es/m/CAEZATCUCGCf82=hxd9N5n6xGHPyYpQnxW8HneeH+uP7yNALkWA@mail.gmail.com --- doc/src/sgml/ref/select.sgml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml index 80bb8adcacc..410c80e730b 100644 --- a/doc/src/sgml/ref/select.sgml +++ b/doc/src/sgml/ref/select.sgml @@ -51,7 +51,7 @@ SELECT [ ALL | DISTINCT [ ON ( expressiontable_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ] [ TABLESAMPLE sampling_method ( argument [, ...] ) [ REPEATABLE ( seed ) ] ] - [ LATERAL ] ( select ) [ AS ] alias [ ( column_alias [, ...] ) ] + [ LATERAL ] ( select ) [ [ AS ] alias [ ( column_alias [, ...] ) ] ] with_query_name [ [ AS ] alias [ ( column_alias [, ...] ) ] ] [ LATERAL ] function_name ( [ argument [, ...] ] ) [ WITH ORDINALITY ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ] @@ -490,8 +490,8 @@ TABLE [ ONLY ] table_name [ * ] output were created as a temporary table for the duration of this single SELECT command. Note that the sub-SELECT must be surrounded by - parentheses, and an alias must be - provided for it. A + parentheses, and an alias can be provided in the same way as for a + table. A VALUES command can also be used here. @@ -2041,6 +2041,16 @@ SELECT 2+2; + + Omitting sub-<command>SELECT</command> aliases in <literal>FROM</literal> + + + According to the SQL standard, a sub-SELECT in the + FROM list must have an alias. In + PostgreSQL, this alias may be omitted. + + + <literal>ONLY</literal> and Inheritance -- cgit v1.2.3