Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wi8nZ-0002bF-Cz for pgsql-bugs@arkaria.postgresql.org; Wed, 07 May 2014 20:50:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Wi8nY-0000UB-7F for pgsql-bugs@arkaria.postgresql.org; Wed, 07 May 2014 20:50:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wi6Pt-0005NN-Dk for pgsql-bugs@postgresql.org; Wed, 07 May 2014 18:18:05 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wi6Pq-0001RW-TM for pgsql-bugs@postgresql.org; Wed, 07 May 2014 18:18:05 +0000 MIME-Version: 1.0 Subject: BUG #10256: COUNT(*) behaves sort of like RANK() when used over a window containing an ORDER BY To: pgsql-bugs@postgresql.org From: arnaud.mouronval@gmail.com Date: Wed, 07 May 2014 18:17:02 +0000 Message-ID: <20140507181702.1397.66739@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 10256 Logged by: Arnaud Mouronval Email address: arnaud.mouronval@gmail.com PostgreSQL version: 9.3.4 Operating system: Windows 8.1 Description: I discovered a problem while using a window that used an ORDER BY clause, and using this window with ROW_NUMBER() and COUNT(*) at the same time. Here is a short SQL script to replicate it : DROP TABLE IF EXISTS tmp_count_window_bug_data; CREATE TABLE tmp_count_window_bug_data (c1 character varying(8), c2 character varying(8)); INSERT INTO tmp_count_window_bug_data (c1, c2) VALUES ('A', 'AA'), ('A', 'AB'), ('B', 'BA'), ('B', 'BB'), ('B', 'BC'), ('B', 'BC'), ('B', 'BD'); SELECT c1, COUNT(*) OVER(PARTITION BY c1), COUNT(*) OVER(PARTITION BY c1 ORDER BY c2) FROM tmp_count_window_bug_data; Result on my machine : "A";2;1 "A";2;2 "B";5;1 "B";5;2 "B";5;4 "B";5;4 "B";5;5 I was expecting to get the same values in the last 2 columns. As you can see, the third column looks much more like a RANK() (except RANK() would have answered 3 instead of 4 for 2 lines). -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs