Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 8BC369FBFB6 for ; Thu, 19 Jul 2007 19:28:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 72549-06 for ; Thu, 19 Jul 2007 19:27:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5629B9FBEEF for ; Thu, 19 Jul 2007 19:28:00 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l6JMRx2i010866; Thu, 19 Jul 2007 18:27:59 -0400 (EDT) To: Howard Smith cc: pgsql-sql@postgresql.org Subject: Re: UNION and LIMIT issue In-reply-to: <469FDF17.9060701@visualmining.com> References: <469FDF17.9060701@visualmining.com> Comments: In-reply-to Howard Smith message dated "Thu, 19 Jul 2007 18:00:55 -0400" Date: Thu, 19 Jul 2007 18:27:59 -0400 Message-ID: <10865.1184884079@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/121 X-Sequence-Number: 28856 Howard Smith 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