Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFJxx-00012F-5y for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Oct 2019 15:21:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFJxu-0001kh-Jr for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Oct 2019 15:21:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFJxu-0001ka-C7 for pgsql-bugs@lists.postgresql.org; Tue, 01 Oct 2019 15:21:26 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFJxr-0007R1-Ks for pgsql-bugs@lists.postgresql.org; Tue, 01 Oct 2019 15:21:25 +0000 Received: from [192.168.127.1] (port=17509 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1iFJxp-000G68-67; Tue, 01 Oct 2019 15:21:21 +0000 Received: from localhost ([127.0.0.1]:53392 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.92.1 (FreeBSD)) (envelope-from ) id 1iFJxp-000DFD-1e; Tue, 01 Oct 2019 15:21:21 +0000 From: Andrew Gierth To: David Raymond Cc: Tom Lane , "pgsql-bugs\@lists.postgresql.org" Subject: Re: BUG #16031: Group by returns duplicate groups In-Reply-To: (David Raymond's message of "Tue, 1 Oct 2019 14:55:37 +0000") Message-ID: <87sgoclcux.fsf@news-spur.riddles.org.uk> References: <16031-4ef55395a5fbb687@postgresql.org> <18850.1569867434@sss.pgh.pa.us> <871rvxm4je.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (berkeley-unix) Date: Tue, 01 Oct 2019 16:21:20 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "David" =3D=3D David Raymond writes: David> c0 | c1_lt | c1_eq | c1_gt | c2_lt | c2_eq= | c2_gt David> -------------+------------+-------+------------+------------+------= -+------------ David> 108,565,086 | 27,900,023 | 25 | 80,665,038 | 27,900,023 | 25= | 80,665,038 David> (1 row) Well those counts look consistent to me. But this is all kinds of messed up: David> testing=3D> with sd as (select name, row_number() over (order by na= me) rnum David> testing(> from big_table) David> testing-> select name from sd David> testing-> where rnum >=3D (select min(rnum) from sd where name=3D'D= K') David> testing-> and rnum <=3D (select max(rnum) from sd where name=3D'DK') David> testing-> and name <> 'DK'; David> name David> ----------------------------------- David> Dk'bus Marine David> Dk's Auto's David> Dk's Bar & Grill David> Dk's Barbers & Stylist David> Dk's Beach Boutique David> Dk's Cabinets & Countertops David> Dk's Cleaning Service David> Dk's Clothing David> Dk's Communications David> Dk's Dancewear & Fitnesswear David> Dk's Dancewear Boutique David> Dk's Discount Dance & Fitnesswear David> DK's Drywall Service David> DK'S DUSTBUSTERS David> Dk's Family Five Star Trophies David> DK's Family Five Star Trophies David> Dk's Food Mart David> Dk'S Group Pte. Ltd. David> Dk's Hair Designs David> Dk's Hair Happenings David> Dk's Hair Supply David> Dk's Home Decor David> DK's Inform=C3=A1tica David> Dk's Janitorial David> DK's Liquors David> Dk's Market David> Dk's Moda Masculina David> Dk's Nails And Spa David> DK's Pawn Shop David> Dk's Pet Grooming David> DK's Quality Service David> DK's Restoration David> Dk's Sports Center David> Dk's Statuary David> Dk's Style Hut David> Dk's Temiskaming Shore Taxi David> Dk's Towing David> DK's Travel David> Dk'Style David> DK'Z Car Wash David> Dk- David> (41 rows) Let's see some more data from that. Do this query: with sd as (select name, row_number() over (order by name) rnum from big_table) select rnum, name, encode(convert_to(name, 'SQL_ASCII'),'escape'), name < 'DK' as lt, name =3D 'DK' as eq, name > 'DK' as gt from sd where rnum >=3D (select min(rnum) from sd where name=3D'DK') and rnum <=3D (select max(rnum) from sd where name=3D'DK'); --=20 Andrew (irc:RhodiumToad)