Обсуждение: subquery in FROM must have an alias

Поиск
Список
Период
Сортировка

subquery in FROM must have an alias

От
"Ashutosh Chauhan"
Дата:
Hi all,

This has been asked before and answered as well.
http://archives.postgresql.org/pgsql-sql/2007-12/msg00002.php but I
still cant figure out why postgres throws this error message even when
I have provided the aliases. My query:

select a,b
    from (billing.item JOIN (
            select *
            from ( billing.invoice JOIN billing.customer
                                   on (id_customer_shipped = customer_uid and
address = 'pgh' ))
                        as temp2 ))
       as temp;

I have two from clauses so I have provided two corresponding alias
names for those two from clauses. But, still I get the error message

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

Any help on this will be greatly appreciated. I am using version 8.3.3
running on ubuntu.

Thanks,
Ashutosh

Re: subquery in FROM must have an alias

От
Stephan Szabo
Дата:
On Sun, 28 Sep 2008, Ashutosh Chauhan wrote:

> Hi all,
>
> This has been asked before and answered as well.
> http://archives.postgresql.org/pgsql-sql/2007-12/msg00002.php but I
> still cant figure out why postgres throws this error message even when
> I have provided the aliases. My query:
>
> select a,b
>     from (billing.item JOIN (
>             select *
>             from ( billing.invoice JOIN billing.customer
>                                    on (id_customer_shipped = customer_uid and
> address = 'pgh' ))
>                         as temp2 ))
>        as temp;
>
> I have two from clauses so I have provided two corresponding alias
> names for those two from clauses.

If you break the above down a bit, you have:

select a,b
from
 (
  billing.item join
  (select * from
   (
    billing.invoice join
    billing.customer
    on (id_customer_shipped = customer_uid and address='pgh')
   )
   as temp2
  )
 )
as temp;

What the system is complaining about is the subselect (select * from ... )
not having an alias. You've aliased the billing.invoice join
billing.customer one and (billing.item join (...)) one, but not the
subselect. In fact, I believe the two aliases you're using aren't strictly
necessary. Also, the above appears to be missing the condition for the
outermost join.

Maybe something like the following will work with a filled in on
condition:

select a,b
from
 (
  billing.item join
  (select * from
   (
    billing.invoice join
    billing.customer
    on (id_customer_shipped = customer_uid and address='pgh')
   )
  )
  as temp
  on (...)
 )



Re: subquery in FROM must have an alias

От
hubert depesz lubaczewski
Дата:
On Sun, Sep 28, 2008 at 12:52:56AM -0400, Ashutosh Chauhan wrote:
> select a,b
>     from (billing.item JOIN (
>             select *
>             from ( billing.invoice JOIN billing.customer
>                                    on (id_customer_shipped = customer_uid and
> address = 'pgh' ))
>                         as temp2 ))
>        as temp;

change last 2 lines to:
                         as temp2 )
        as temp);

best regards,

depesz


--
Linkedin: http://www.linkedin.com/in/depesz  /  blog: http://www.depesz.com/
jid/gtalk: depesz@depesz.com / aim:depeszhdl / skype:depesz_hdl / gg:6749007

Re: subquery in FROM must have an alias

От
"Ashutosh Chauhan"
Дата:
Thanks to Stephan and Hubert for their replies. Using your answers I
was able to solve the problem. It turned out that its a natural join
that I wanted.

Thanks for quick help,
Ashutosh

On Sun, Sep 28, 2008 at 10:18, Stephan Szabo
<sszabo@megazone.bigpanda.com> wrote:
> On Sun, 28 Sep 2008, Ashutosh Chauhan wrote:
>
>> Hi all,
>>
>> This has been asked before and answered as well.
>> http://archives.postgresql.org/pgsql-sql/2007-12/msg00002.php but I
>> still cant figure out why postgres throws this error message even when
>> I have provided the aliases. My query:
>>
>> select a,b
>>       from (billing.item JOIN (
>>                       select *
>>                       from ( billing.invoice JOIN billing.customer
>>                                                  on (id_customer_shipped = customer_uid and
>> address = 'pgh' ))
>>                         as temp2 ))
>>        as temp;
>>
>> I have two from clauses so I have provided two corresponding alias
>> names for those two from clauses.
>
> If you break the above down a bit, you have:
>
> select a,b
> from
>  (
>  billing.item join
>  (select * from
>   (
>    billing.invoice join
>    billing.customer
>    on (id_customer_shipped = customer_uid and address='pgh')
>   )
>   as temp2
>  )
>  )
> as temp;
>
> What the system is complaining about is the subselect (select * from ... )
> not having an alias. You've aliased the billing.invoice join
> billing.customer one and (billing.item join (...)) one, but not the
> subselect. In fact, I believe the two aliases you're using aren't strictly
> necessary. Also, the above appears to be missing the condition for the
> outermost join.
>
> Maybe something like the following will work with a filled in on
> condition:
>
> select a,b
> from
>  (
>  billing.item join
>  (select * from
>   (
>    billing.invoice join
>    billing.customer
>    on (id_customer_shipped = customer_uid and address='pgh')
>   )
>  )
>  as temp
>  on (...)
>  )
>
>
>