pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedSELECT do not return all rows depending on selected columns
2+ messages / 2 participants
[nested] [flat]
* SELECT do not return all rows depending on selected columns
@ 2019-01-04 15:18 Fabrice LEGROS <fabrice.legros@abbd.fr>
2019-01-04 18:04 ` Re: SELECT do not return all rows depending on selected columns Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Fabrice LEGROS @ 2019-01-04 15:18 UTC (permalink / raw)
To: pgsql-bugs
Hello,
In attachment, there is 2 files :
* init.sql to create and fill a table
* request.sql with a select on this table
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).
Tested on "PostgreSQL 9.6.10 on x86_64-pc-linux-gnu (Debian 9.6.10-1.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit"
Also tested on "PostgreSQL 10.5 (Debian 10.5-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit"
Same behavior, but with 2133 rows for the select with 2 columns.
Regards,
Fabrice Legros.
Attachments:
testdata.7z (application/octet-stream, 57.0K) download
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: SELECT do not return all rows depending on selected columns
2019-01-04 15:18 SELECT do not return all rows depending on selected columns Fabrice LEGROS <fabrice.legros@abbd.fr>
@ 2019-01-04 18:04 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2019-01-04 18:04 UTC (permalink / raw)
To: Fabrice LEGROS <fabrice.legros@abbd.fr>; +Cc: pgsql-bugs
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2019-01-04 18:04 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-01-04 15:18 SELECT do not return all rows depending on selected columns Fabrice LEGROS <fabrice.legros@abbd.fr>
2019-01-04 18:04 ` Tom Lane <tgl@sss.pgh.pa.us>
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