Re: UNION and LIMIT issue

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Howard Smith <hsmith(at)visualmining(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: UNION and LIMIT issue
Date: 2007-07-19 22:27:59
Message-ID: 10865.1184884079@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Howard Smith <hsmith(at)visualmining(dot)com> writes:
> SELECT name,quantity FROM fruit limit 3
> UNION
> select name,CAST(SUM(quantity) as integer) from (
> select Cast('Other' as varchar) as name,quantity from fruit
> limit ALL offset 3
> ) w group by name

You need parentheses:

(SELECT ... limit 3) UNION ...

ISTM that a LIMIT without an ORDER BY is a pretty bad idea, btw.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message ljb 2007-07-20 01:41:05 Re: UNION and LIMIT issue
Previous Message Howard Smith 2007-07-19 22:00:55 UNION and LIMIT issue