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

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: Stefan Weiss <krewecherl(at)gmail(dot)com>
Subject: Re: Column "..." does not exist (view + union)
Date: 2011-12-17 23:38:43
Message-ID: 201112171538.43512.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Saturday, December 17, 2011 2:21:30 pm Stefan Weiss wrote:

>
> I know, but the problem only occurs when I want to sort by a column
> which hasn't been selected, and thus cannot be referred to by its index.
> For normal (non-union) queries, this is possible:
>
> SELECT relname
> FROM pg_class
> WHERE relhasindex
> ORDER BY relpages;
>
> In this trivial case, PostgreSQL knows where to look for "relpages".
> Not so in a union:
>
> SELECT relname
> FROM pg_class
> WHERE relhasindex
> UNION
> SELECT relname
> FROM pg_class
> WHERE relhasoids
> ORDER BY relpages;
>
> (ERROR: column "relpages" does not exist)
>
> I understand the error now (I think), and I know how to avoid it.

SELECT relname
FROM pg_class
WHERE relhasindex
UNION
(SELECT relname
FROM pg_class
WHERE relhasoids
ORDER BY relpages);

>
>
> thanks,
> stefan

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Brent Dombrowski 2011-12-18 02:58:18 Re: Column "..." does not exist (view + union)
Previous Message Bèrto ëd Sèra 2011-12-17 23:15:49 Re: Column "..." does not exist (view + union)