Re: union all bug?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: "Hackers (PostgreSQL)" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: union all bug?
Date: 2006-06-18 16:31:01
Message-ID: 28986.1150648261@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Joe Conway <mail(at)joeconway(dot)com> writes:
> I was trying to work around limitations with "partitioning" of tables
> using constraint exclusion, when I ran across this little oddity:

I think you're under a misimpression about the syntax behavior of ORDER
BY and UNION. Per spec, ORDER BY binds less tightly than UNION, thus

select foo union select bar order by x

means

(select foo union select bar) order by x

If you want to apply ORDER BY to either arm of a union individually,
you need parentheses, eg

(select foo order by x) union (select bar order by x)

(Note that this construct fails to guarantee that the output of the
union will be sorted by x!) LIMIT is not in the spec but we treat
it like ORDER BY for this purpose.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gurjeet Singh 2006-06-18 16:43:13 Re: union all bug?
Previous Message Joe Conway 2006-06-18 15:36:30 union all bug?