Received: from sss2.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by hub.org (8.9.3/8.9.3) with ESMTP id PAA69915 for ; Tue, 28 Dec 1999 15:15:02 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss2.sss.pgh.pa.us (8.9.3/8.9.3) with ESMTP id PAA28954; Tue, 28 Dec 1999 15:13:25 -0500 (EST) To: "M. Scott Smith" cc: pgsql-sql@postgreSQL.org Subject: Re: [SQL] Problem with limit / union / etc. In-reply-to: <199912281615.LAA13003@afterlife.ncsc.mil> References: <199912281615.LAA13003@afterlife.ncsc.mil> Comments: In-reply-to "M. Scott Smith" message dated "Tue, 28 Dec 1999 11:17:43 -0500" Date: Tue, 28 Dec 1999 15:13:25 -0500 Message-ID: <28951.946412005@sss.pgh.pa.us> From: Tom Lane "M. Scott Smith" writes: > What I want to do is pull out upcoming events, limiting the number > returned. The following query is my attempt to do that. The > first select selects all events that have a URL associated with > them; the second query selects all events that DON'T have a URL > associated with them; the results are combined together. My > hope is that the order by/limit clause will limit the results returned > after they are combined, but it seems to be ignoring this. Yeah, there's a bug in 6.5.* that causes it to ignore LIMIT on a UNION. I fixed it a couple months ago, but there's been no new release since then. Here's the patch, if you want to patch your copy: *** src/backend/rewrite/rewriteHandler.c~ Sun Jul 11 13:54:30 1999 --- src/backend/rewrite/rewriteHandler.c Tue Oct 19 00:38:05 1999 *************** *** 2859,2864 **** --- 2859,2866 ---- bool isBinary, isPortal, isTemp; + Node *limitOffset, + *limitCount; CmdType commandType = CMD_SELECT; List *rtable_insert = NIL; *************** *** 2909,2914 **** --- 2911,2918 ---- isBinary = parsetree->isBinary; isPortal = parsetree->isPortal; isTemp = parsetree->isTemp; + limitOffset = parsetree->limitOffset; + limitCount = parsetree->limitCount; /* * The operator tree attached to parsetree->intersectClause is still *************** *** 3094,3099 **** --- 3098,3105 ---- result->isPortal = isPortal; result->isBinary = isBinary; result->isTemp = isTemp; + result->limitOffset = limitOffset; + result->limitCount = limitCount; /* * The relation to insert into is attached to the range table of the regards, tom lane