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

2007-01-12 Thread Bruce Momjian
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

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

2007-01-11 Thread Bruce Momjian
Tom Lane wrote: Michael Glaesemann [EMAIL PROTECTED] writes: On Dec 26, 2006, at 18:39 , Mike Benoit wrote: ERROR: ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns Even though state is a column in both tables, the order by is using an expression,

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

2007-01-11 Thread Mike Benoit
On Thu, 2007-01-11 at 13:44 -0500, Bruce Momjian wrote: Tom Lane wrote: Michael Glaesemann [EMAIL PROTECTED] writes: On Dec 26, 2006, at 18:39 , Mike Benoit wrote: ERROR: ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns Even though state is a

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

2007-01-11 Thread Bruce Momjian
Mike Benoit wrote: That helps some, but I'm sure it could be even more clear. The main issue is that you can't order by an expression computed by unions, correct? So couldn't the error message by something like: ORDER BY on a UNION/INTERSECT/EXCEPT result must match existing result

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

2007-01-11 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] 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. regards, tom lane ---(end of

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

2007-01-11 Thread Bruce Momjian
Tom Lane wrote: Bruce Momjian [EMAIL PROTECTED] 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

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

2007-01-11 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] writes: 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 does not meet the style guidelines.

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

2007-01-11 Thread Alvaro Herrera
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

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

2007-01-11 Thread Bruce Momjian
Tom Lane wrote: Bruce Momjian [EMAIL PROTECTED] writes: 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 does not meet the style

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

2007-01-11 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] writes: Where are the style guidelines? I looked before but can't find them. http://developer.postgresql.org/pgdocs/postgres/error-style-guide.html regards, tom lane ---(end of

[GENERAL] ORDER BY col is NULL in UNION causes error?

2006-12-26 Thread Mike Benoit
I asked about this on IRC and the helpful people online at the time didn't seem to have an explanation. Works - select * from income_tax_rate_us order by state is null; Works - select * from income_tax_rate_us UNION select * from income_tax_rate_us

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

2006-12-26 Thread Michael Glaesemann
On Dec 26, 2006, at 18:39 , Mike Benoit wrote: Fails - select * from income_tax_rate_us UNION select * from income_tax_rate_us order by state is null; ERROR: ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns Even though state is a column

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

2006-12-26 Thread Tom Lane
Michael Glaesemann [EMAIL PROTECTED] writes: On Dec 26, 2006, at 18:39 , Mike Benoit wrote: ERROR: ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns Even though state is a column in both tables, the order by is using an expression, rather than a column. ...