mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-02 20:56:54 +02:00
Doc: update queries.sgml for optional subquery aliases.
Commit bcedd8f5f
made subquery aliases optional in the FROM clause.
It missed updating this part of the docs, though.
This commit is contained in:
parent
ccc59a83cd
commit
ec25ba624e
@ -588,8 +588,6 @@ SELECT * FROM my_table AS m WHERE my_table.a > 5; -- wrong
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT * FROM people AS mother JOIN people AS child ON mother.id = child.mother_id;
|
SELECT * FROM people AS mother JOIN people AS child ON mother.id = child.mother_id;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
Additionally, an alias is required if the table reference is a
|
|
||||||
subquery (see <xref linkend="queries-subqueries"/>).
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -639,9 +637,9 @@ SELECT a.* FROM (my_table AS a JOIN your_table AS b ON ...) AS c
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
Subqueries specifying a derived table must be enclosed in
|
Subqueries specifying a derived table must be enclosed in
|
||||||
parentheses and <emphasis>must</emphasis> be assigned a table
|
parentheses. They may be assigned a table alias name, and optionally
|
||||||
alias name (as in <xref linkend="queries-table-aliases"/>). For
|
column alias names (as in <xref linkend="queries-table-aliases"/>).
|
||||||
example:
|
For example:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
FROM (SELECT * FROM table1) AS alias_name
|
FROM (SELECT * FROM table1) AS alias_name
|
||||||
</programlisting>
|
</programlisting>
|
||||||
@ -660,10 +658,18 @@ FROM (SELECT * FROM table1) AS alias_name
|
|||||||
FROM (VALUES ('anne', 'smith'), ('bob', 'jones'), ('joe', 'blow'))
|
FROM (VALUES ('anne', 'smith'), ('bob', 'jones'), ('joe', 'blow'))
|
||||||
AS names(first, last)
|
AS names(first, last)
|
||||||
</programlisting>
|
</programlisting>
|
||||||
Again, a table alias is required. Assigning alias names to the columns
|
Again, a table alias is optional. Assigning alias names to the columns
|
||||||
of the <command>VALUES</command> list is optional, but is good practice.
|
of the <command>VALUES</command> list is optional, but is good practice.
|
||||||
For more information see <xref linkend="queries-values"/>.
|
For more information see <xref linkend="queries-values"/>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
According to the SQL standard, a table alias name must be supplied
|
||||||
|
for a subquery. <productname>PostgreSQL</productname>
|
||||||
|
allows <literal>AS</literal> and the alias to be omitted, but
|
||||||
|
writing one is good practice in SQL code that might be ported to
|
||||||
|
another system.
|
||||||
|
</para>
|
||||||
</sect3>
|
</sect3>
|
||||||
|
|
||||||
<sect3 id="queries-tablefunctions">
|
<sect3 id="queries-tablefunctions">
|
||||||
|
Loading…
Reference in New Issue
Block a user