From: Adrian Klaver <adrian.klaver@gmail.com>
To: pgsql-sql@postgresql.org
Cc: Stefan Weiss <krewecherl@gmail.com>
Subject: Re: Column "..." does not exist (view + union)
Date: Sat, 17 Dec 2011 15:38:43 -0800
Message-ID: <201112171538.43512.adrian.klaver@gmail.com> (raw)
In-Reply-To: <4EED15EA.6000507@gmail.com>
References: <4EEC0533.9050007@gmail.com>
<CAKwGa_9D9M6V+bYJwayx_JtD1Tq3oQ0vouSXSshebQ8bbiJGMg@mail.gmail.com>
<4EED15EA.6000507@gmail.com>
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.klaver@gmail.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: adrian.klaver@gmail.com, krewecherl@gmail.com
Subject: Re: Column "..." does not exist (view + union)
In-Reply-To: <201112171538.43512.adrian.klaver@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox