@@ -588,8 +588,6 @@ SELECT * FROM my_table AS m WHERE my_table.a > 5; -- wrong
588
588
<programlisting>
589
589
SELECT * FROM people AS mother JOIN people AS child ON mother.id = child.mother_id;
590
590
</programlisting>
591
- Additionally, an alias is required if the table reference is a
592
- subquery (see <xref linkend="queries-subqueries"/>).
593
591
</para>
594
592
595
593
<para>
@@ -639,9 +637,9 @@ SELECT a.* FROM (my_table AS a JOIN your_table AS b ON ...) AS c
639
637
640
638
<para>
641
639
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:
645
643
<programlisting>
646
644
FROM (SELECT * FROM table1) AS alias_name
647
645
</programlisting>
@@ -660,10 +658,18 @@ FROM (SELECT * FROM table1) AS alias_name
660
658
FROM (VALUES ('anne', 'smith'), ('bob', 'jones'), ('joe', 'blow'))
661
659
AS names(first, last)
662
660
</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
664
662
of the <command>VALUES</command> list is optional, but is good practice.
665
663
For more information see <xref linkend="queries-values"/>.
666
664
</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>
667
673
</sect3>
668
674
669
675
<sect3 id="queries-tablefunctions">
0 commit comments