On Thu, Jul 01, 2004 at 15:19:32 +0200,
Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org> wrote:
>
> Looking again at the doc and the example I now know why it can't parse
> it. The example when simplified is:
>
> SELECT *
> FROM (select 1 ORDER BY 1
> UNION ALL
> select 2) AS x;
>
> and it does not parse since the there is an ORDER BY in the first query.
> If we look at the doc page then the UNION comes before the ORDER BY, so it
> is in fact an invalid query (I've not checke the standard, just the select
> doc page).
>
> If you put a () around the first (inner) select it all works. But why
> is the order by there at all? The order of the rows from the UNION ALL can
> (in theory) be random anyway, right?
If DISTINCT ON or LIMIT was used in inner select, then the ORDER BY would
be relevant; so you can't just blindly remove ORDER BY when it is part of
a union.
In response to
Responses
pgsql-hackers by date
| Next: | From: Dennis Bjorklund | Date: 2004-07-01 16:32:30 |
| Subject: Re: Bug with view definitions? |
| Previous: | From: Justin Clift | Date: 2004-07-01 15:04:55 |
| Subject: Re: Bug with view definitions? |