Re: Bug with view definitions? - Mailing list pgsql-hackers

From Bruno Wolff III
Subject Re: Bug with view definitions?
Date
Msg-id 20040701163053.GB1438@wolff.to
Whole thread Raw
In response to Re: Bug with view definitions?  (Dennis Bjorklund <db@zigo.dhs.org>)
List pgsql-hackers
On Thu, Jul 01, 2004 at 15:19:32 +0200, Dennis Bjorklund <db@zigo.dhs.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.


pgsql-hackers by date:

Previous
From: Dennis Bjorklund
Date:
Subject: Re: Bug with view definitions?
Next
From: Tom Lane
Date:
Subject: Re: Adding column comment to information_schema.columns