Skip to content

Commit ec25ba6

Browse files
committed
Doc: update queries.sgml for optional subquery aliases.
Commit bcedd8f made subquery aliases optional in the FROM clause. It missed updating this part of the docs, though.
1 parent ccc59a8 commit ec25ba6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

doc/src/sgml/queries.sgml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,6 @@ SELECT * FROM my_table AS m WHERE my_table.a > 5; -- wrong
588588
<programlisting>
589589
SELECT * FROM people AS mother JOIN people AS child ON mother.id = child.mother_id;
590590
</programlisting>
591-
Additionally, an alias is required if the table reference is a
592-
subquery (see <xref linkend="queries-subqueries"/>).
593591
</para>
594592

595593
<para>
@@ -639,9 +637,9 @@ SELECT a.* FROM (my_table AS a JOIN your_table AS b ON ...) AS c
639637

640638
<para>
641639
Subqueries specifying a derived table must be enclosed in
642-
parentheses and <emphasis>must</emphasis> be assigned a table
643-
alias name (as in <xref linkend="queries-table-aliases"/>). For
644-
example:
640+
parentheses. They may be assigned a table alias name, and optionally
641+
column alias names (as in <xref linkend="queries-table-aliases"/>).
642+
For example:
645643
<programlisting>
646644
FROM (SELECT * FROM table1) AS alias_name
647645
</programlisting>
@@ -660,10 +658,18 @@ FROM (SELECT * FROM table1) AS alias_name
660658
FROM (VALUES ('anne', 'smith'), ('bob', 'jones'), ('joe', 'blow'))
661659
AS names(first, last)
662660
</programlisting>
663-
Again, a table alias is required. Assigning alias names to the columns
661+
Again, a table alias is optional. Assigning alias names to the columns
664662
of the <command>VALUES</command> list is optional, but is good practice.
665663
For more information see <xref linkend="queries-values"/>.
666664
</para>
665+
666+
<para>
667+
According to the SQL standard, a table alias name must be supplied
668+
for a subquery. <productname>PostgreSQL</productname>
669+
allows <literal>AS</literal> and the alias to be omitted, but
670+
writing one is good practice in SQL code that might be ported to
671+
another system.
672+
</para>
667673
</sect3>
668674

669675
<sect3 id="queries-tablefunctions">

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy