Re: Column "..." does not exist (view + union)

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Column "..." does not exist (view + union)
Date: 2011-12-17 09:02:46
Message-ID: 20111217090246.GA12209@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Stefan Weiss <krewecherl(at)gmail(dot)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°

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Klingler 2011-12-17 10:33:06 Natural sort order
Previous Message Stefan Weiss 2011-12-17 02:57:55 Column "..." does not exist (view + union)