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

From Andreas Kretschmer
Subject Re: Column "..." does not exist (view + union)
Date
Msg-id 20111217090246.GA12209@tux
Whole thread Raw
In response to Column "..." does not exist (view + union)  (Stefan Weiss <krewecherl@gmail.com>)
Responses Re: Column "..." does not exist (view + union)
List pgsql-sql
Stefan Weiss <krewecherl@gmail.com> wrote:

> 
> - running this query -
> 
>     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". Rewrite your query to something like:

select name from (select name, ctype from ... union select name, ctype from ...)
foo order by ctype



Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°


pgsql-sql by date:

Previous
From: Stefan Weiss
Date:
Subject: Column "..." does not exist (view + union)
Next
From: Richard Klingler
Date:
Subject: Natural sort order