Re: ORDER BY col is NULL in UNION causes error?

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Mike Benoit <ipso(at)snappymail(dot)ca>, Michael Glaesemann <grzm(at)seespotcode(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: ORDER BY col is NULL in UNION causes error?
Date: 2007-01-11 20:04:25
Message-ID: 200701112004.l0BK4Pa27274@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Well, it can be an expression _if_ the expression _matches_ an existing
> > UNION column.
>
> You're mistaken. It has to be *an output column name*. Not anything else.

Yea, I was thinking of this:

SELECT *, state IS NULL AS state_is_null
FROM income_tax_rate_us
UNION
SELECT *, state IS NULL AS state_is_null
FROM income_tax_rate_us
ORDER BY state_is_null

Here the column result is an expression, and you reference that.
Updated wording:

test=> select * from test union select * from test order by x is null;
ERROR: A UNION/INTERSECT/EXCEPT ORDER BY cannot use expressions or functions, only result column names

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-01-11 20:14:37 Re: Checkpoint request failed on version 8.2.1.
Previous Message Patrick Earl 2007-01-11 19:37:26 Re: Checkpoint request failed on version 8.2.1.