From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Richard Huxton <dev(at)archonet(dot)com> |
Cc: | Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>, PostgreSQL-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: UNION problem |
Date: | 2003-02-04 16:13:24 |
Message-ID: | 14749.1044375204@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Richard Huxton <dev(at)archonet(dot)com> writes:
> Since the two queries work separately, I'd guess PG is trying to locate
> prod_type_id via a different route when unioned. What happens if you qualify
> all the column-names?
ORDER BY applied to a UNION result can only order by the column names
visible in the UNION result. Consider for example
SELECT x1 AS a FROM foo
UNION
SELECT y1 AS a FROM bar
ORDER BY ???
where foo and bar have no column names in common. The *only* thing
that's sensible to order by is "a" --- and no qualification, mind you.
Anything else you might try to order by is not available in one or the
other arm of the UNION.
The SQL92 spec is very rigid about this, and so is Postgres. You could
imagine ordering by, say, UPPER(a), but we don't support that extension
at present (unlike the situation for ORDER BY in non-UNION queries,
where we're quite lax).
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-02-04 16:24:03 | Re: Q: explain on delete |
Previous Message | Bruno Wolff III | 2003-02-04 16:04:31 | Re: Dealing with complex queries |