Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uae13-0002yJ-HI for pgsql-bugs@arkaria.postgresql.org; Fri, 10 May 2013 03:29:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Uae12-0008V6-Ty for pgsql-bugs@arkaria.postgresql.org; Fri, 10 May 2013 03:29:04 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uae12-0008V1-A8 for pgsql-bugs@postgresql.org; Fri, 10 May 2013 03:29:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uae10-0005fi-6m for pgsql-bugs@postgresql.org; Fri, 10 May 2013 03:29:03 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r4A3SoII021697; Thu, 9 May 2013 23:28:50 -0400 (EDT) From: Tom Lane To: marc@bloodnok.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8144: Problem with rank window function and CTEs In-reply-to: References: Comments: In-reply-to marc@bloodnok.com message dated "Fri, 10 May 2013 02:16:57 -0000" Date: Thu, 09 May 2013 23:28:50 -0400 Message-ID: <21696.1368156530@sss.pgh.pa.us> X-Pg-Spam-Score: -3.1 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org marc@bloodnok.com writes: > I have a query in which I want to use the result of a window function to > isolate the most relevant results. While I was trying to develop and test > the query, I discovered what looks like a bug in the results of the rank() > function. This has been tried with the same results on 9.1.9 and 9.2.4 Well, you didn't provide enough information for somebody else to reproduce the problem, but just looking at this I see no particular reason to think there's a bug. In the first case, the "where ao.org_id = 20150" clause filters rows before the rank() is taken, whereas in the second case it filters after the rank() function. I think the larger rank values indicate that there are other rows with different org_id but the same item_id, which you won't see in the final output in either case --- but in the second query, the rank() function does see them. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs