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

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 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-12 19:34:26
Message-ID: 200701121934.l0CJYQ327928@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alvaro Herrera wrote:
> Bruce Momjian wrote:
>
> > 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
>
> This seems at odds with our message style guidelines. I'd suggest
> putting the actual error message in errmsg() and the rest as a errhint,
> maybe
>
> (errmsg("invalid UNION/INTERSECT/EXCEPT ORDER BY clause"),
> errhint("You may specify only output result column names in the ORDER BY clauses."))
>
> or something like that.

Updated wording:

test=> SELECT * FROM test UNION SELECT * FROM test ORDER BY X IS NULL;
ERROR: invalid UNION/INTERSECT/EXCEPT ORDER BY clause
DETAIL: Only result column names can be used, not expressions or functions.
HINT: Add the expression/function to every SELECT, or move the UNION into a FROM clause.

--
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

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2007-01-12 20:13:44 Re: [GENERAL] Corrupt database? 8.1/FreeBSD6.0
Previous Message Brandon Aiken 2007-01-12 18:29:29 Re: Version 8.2 for HP-UX