Re: alias required by standard or PostgreSQL?

Lists: pgsql-sql
From: "Joost Kraaijeveld" <J(dot)Kraaijeveld(at)Askesis(dot)nl>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: alias required by standard or PostgreSQL?
Date: 2007-12-03 05:52:29
Message-ID: 1196661149.5542.33.camel@panoramix.askesis.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Hi,

If I run the query

"select * from (select * from table_name)"

PostgreSQL complains with

ERROR: subquery in FROM must have an alias
HINT: For example, FROM (SELECT ...) [AS] foo.

Is the alias required by the ISO standard or is this a PostgreSQL
requirement?

TIA

--
Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
web: www.askesis.nl


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Joost Kraaijeveld" <J(dot)Kraaijeveld(at)Askesis(dot)nl>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: alias required by standard or PostgreSQL?
Date: 2007-12-03 06:13:29
Message-ID: 9788.1196662409@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

"Joost Kraaijeveld" <J(dot)Kraaijeveld(at)Askesis(dot)nl> writes:
> "select * from (select * from table_name)"

> PostgreSQL complains with

> ERROR: subquery in FROM must have an alias
> HINT: For example, FROM (SELECT ...) [AS] foo.

> Is the alias required by the ISO standard

Yes. A FROM-clause entry is defined as

<table reference> ::=
<table name> [ [ AS ] <correlation name>
[ <left paren> <derived column list> <right paren> ] ]
| <derived table> [ AS ] <correlation name>
[ <left paren> <derived column list> <right paren> ]
| <joined table>

<derived table> ::= <table subquery>

Note that the brackets show that a <correlation name> (ie, an alias)
is optional for a regular table, but not for a subquery.

regards, tom lane