pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Johnston <polobo@yahoo.com>
To: 'Tom Lane' <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6131: Query Returning Incorrect Results
Date: Tue, 26 Jul 2011 19:57:42 -0400
Message-ID: <00db01cc4bef$cf1a0e40$6d4e2ac0$@yahoo.com> (raw)
In-Reply-To: <19689.1311723714@sss.pgh.pa.us>
References: <201107262228.p6QMSj33073313@wwwmaster.postgresql.org>
	<19689.1311723714@sss.pgh.pa.us>



-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
Sent: Tuesday, July 26, 2011 7:42 PM
To: David Johnston
Cc: pgsql-bugs@postgresql.org
Subject: Re: [BUGS] BUG #6131: Query Returning Incorrect Results 

"David Johnston" <polobo@yahoo.com> writes:
> The embedded script exhibits some strange behavior.  When the query is 
> run the [adjustment_paid] column for [technician] "6338B" should show +/-
25.00.
>  Instead, if I run the last query immediately after creating the 
> schema and inserting the data the results I get for that technician is 
> 0.00 for both records.  However, if I continue to run the query, or 
> explicitly run ANALYZE , I then get the correct results.

Interesting example.  I don't believe it's a Postgres bug though, but rather
indeterminism in your query.  If you pull out the subquery that is being fed
to the window aggregate (row_number()):

SELECT s_id, date_reference, accountnumber, technician, rate_paid, COUNT(*)
AS rate_count FROM laborwip_payroll_ticket GROUP BY s_id, date_reference,
accountnumber, technician, rate_paid ORDER BY s_id, date_reference,
accountnumber, technician, rate_count DESC;

you will find that it produces slightly different output row ordering before
and after the ANALYZE.  I get

... you get only the first one of those two rows.  And then your upper
query's results vary depending on which rate_paid you got.  So basically you
need to add more columns to the window aggregate PARTITION/ORDER BY clauses
to make the result more deterministic.

-----------------------------------------

Now I feel like a schmuck...sorry for the noise.  I should/do know better
but my mind is fried.  Thank you so much for the quick response.

David J.







view thread (3+ messages)

Message-ID: <00db01cc4bef$cf1a0e40$6d4e2ac0$@yahoo.com>
Permalink:  ../00db01cc4bef$cf1a0e40$6d4e2ac0$@yahoo.com/
Also on:    postgresql.org/message-id/00db01cc4bef$cf1a0e40$6d4e2ac0$@yahoo.com

 · 

reply

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: polobo@yahoo.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #6131: Query Returning Incorrect Results
  In-Reply-To: <00db01cc4bef$cf1a0e40$6d4e2ac0$@yahoo.com>
  References: <201107262228.p6QMSj33073313@wwwmaster.postgresql.org> <19689.1311723714@sss.pgh.pa.us> <00db01cc4bef$cf1a0e40$6d4e2ac0$@yahoo.com>

* 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