From: Tom Lane <tgl@sss.pgh.pa.us>
To: Fabrice LEGROS <fabrice.legros@abbd.fr>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: SELECT do not return all rows depending on selected columns
Date: Fri, 04 Jan 2019 13:04:41 -0500
Message-ID: <9817.1546625081@sss.pgh.pa.us> (raw)
In-Reply-To: <DB6PR0301MB2552152ABBF61DAF79156B83938E0@DB6PR0301MB2552.eurprd03.prod.outlook.com>
References: <DB6PR0301MB2552152ABBF61DAF79156B83938E0@DB6PR0301MB2552.eurprd03.prod.outlook.com>
Fabrice LEGROS <fabrice.legros@abbd.fr> writes:
> The request return 2122 rows, if I remove the second column (v2.journalcode) 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 != 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, fabrice.legros@abbd.fr
Subject: Re: SELECT do not return all rows depending on selected columns
In-Reply-To: <9817.1546625081@sss.pgh.pa.us>
References: <DB6PR0301MB2552152ABBF61DAF79156B83938E0@DB6PR0301MB2552.eurprd03.prod.outlook.com> <9817.1546625081@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox