Re: Column "..." does not exist (view + union) - Mailing list pgsql-sql

From Stefan Weiss
Subject Re: Column "..." does not exist (view + union)
Date
Msg-id 4EECA699.2020700@gmail.com
Whole thread Raw
In response to Re: Column "..." does not exist (view + union)  (Andreas Kretschmer <akretschmer@spamfence.net>)
Responses Re: Column "..." does not exist (view + union)
List pgsql-sql
On 2011-12-17 10:02, Andreas Kretschmer wrote:
> Stefan Weiss <krewecherl@gmail.com> wrote:
>> 
>>     SELECT  name
>>       FROM  dossier_contact_v
>>      WHERE  dossier_id = 56993
>>        AND  ctype = 234
>> UNION
>>     SELECT  name
>>       FROM  dossier_contact_v
>>      WHERE  dossier_id = -1
>>        AND  ctype = -1
>> ORDER BY ctype;
>> 
>> - fails with the following error message:
>> 
>> ERROR:  column "ctype" does not exist
>> LINE 10: ORDER BY ctype;
> 
> The reult table doesn't contain a column "ctype", it contains only
> "name". [...]

I see. So this has to do with the union; after combining the two
queries, the tables from the FROM clauses are no longer available.
Thanks, that explains it.


- stefan


pgsql-sql by date:

Previous
From: Richard Klingler
Date:
Subject: Natural sort order
Next
From: Filip Rembiałkowski
Date:
Subject: Re: Natural sort order