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 1gfTpz-0002Bw-6M for pgsql-bugs@arkaria.postgresql.org; Fri, 04 Jan 2019 18:04:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gfTpx-00022V-Ut for pgsql-bugs@arkaria.postgresql.org; Fri, 04 Jan 2019 18:04:49 +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 1gfTpx-0001zV-Nf for pgsql-bugs@lists.postgresql.org; Fri, 04 Jan 2019 18:04:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gfTpv-0003LZ-Mq for pgsql-bugs@postgresql.org; Fri, 04 Jan 2019 18:04:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x04I4fHo009818; Fri, 4 Jan 2019 13:04:41 -0500 From: Tom Lane To: Fabrice LEGROS cc: "pgsql-bugs@postgresql.org" Subject: Re: SELECT do not return all rows depending on selected columns In-reply-to: References: Comments: In-reply-to Fabrice LEGROS message dated "Fri, 04 Jan 2019 15:18:31 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9816.1546625081.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Jan 2019 13:04:41 -0500 Message-ID: <9817.1546625081@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Fabrice LEGROS writes: > The request return 2122 rows, if I remove the second column (v2.journalc= ode) from the select I get 2801 rows (which is the expected result). I think your problem here is an underspecified query. The ecriturenum column is not unique, hence "LAG(ecriturenum) OVER ( ORDER BY ecriturenum ASC )" is not entirely determinate, hence the set of rows selected by "WHERE ecriturenum - ecriturenumprev !=3D 1" isn't determinate. I get slightly different counts than you mention, and I imagine the apparent dependency on the number of output columns has to do with the volume of data passing through the sort steps being different, causing the sorts to do different arbitrary things with equal-keyed rows. If I change those OVER clauses to be like LAG(ecriturenum) OVER ( ORDER BY ecriturenum ASC, line_number ) then I get determinate results (since line_number is unique). regards, tom lane