Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id BC3D5B5D91F for ; Tue, 26 Jul 2011 20:57:56 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 15159-04 for ; Tue, 26 Jul 2011 23:57:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtp103.prem.mail.ac4.yahoo.com (smtp103.prem.mail.ac4.yahoo.com [76.13.13.42]) by mail.postgresql.org (Postfix) with SMTP id 7CE94B5D80A for ; Tue, 26 Jul 2011 20:57:50 -0300 (ADT) Received: (qmail 19169 invoked from network); 26 Jul 2011 23:57:49 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=0NskTwNDLhdobUJ5ouHqmp9vQHawujujOLUnqNOLXuqMWLnVmCIix0mO34iC0UX/BD8QwwRurGB97+G8jONxF2BgMGfdZN31Jxgk6VRcw/h1fXPouahfvj9wz+w6Y3pQv0NeBwS54uCHPt9fVdXDsEWYJyQ0Cg26Z8Mx2DcBxLI= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1311724669; bh=WAoFoFKhIrhiDiOVn6X7EOidLTwmCYnf+hpGcv1flPc=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=naBxJsEHK/MV7eysX8HAptgpltcMwWDzD1C0m+HjjwTjQUBaRNaCGc2aGJ2HOUPPJnHNNPujXJF8XN0us4siHDEtdk0vV/nqcUrc9zlnCNFvuo+jrxVXvXUPahiNb9ILltWIFg137RelpJrrYb3ktHT5nUrMp9hCYrOrnjjSLIs= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 7ywAu98VM1ll.dWamyZWZqGyOOF.Hzxsl71bQSZf.f6k7rW R1.Ou5EDf_nqIhspdKy4cq6WMGJm7xRBvCmV0LeBIuCTgwit4bcZCNS2GSXC 6ZF6dMQhSrrWVVCMYJB6FjwriaukiaRHO07NgLz3_IKqIbLngL9vQeecazqF mV8bMQQL4V8rqafCKk45Hg4xsSbiLJ4dYmuffFFUeB.HcT.L9LCD4BN4x6DZ gSKiAOaEqTitBfg5xvNJbWSw7vuARzQh49Bkc_aAhOpAD10GyD4AvZ18Ek.R keJ1D.3qNwM_0fPy.3wA6.QfFTgI2lOMy35JP9wTD1YMDl8xGXxxdssTP1jt XHhh05W9q0I90YBqfWlhdzw-- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@66.67.24.143 with login) by smtp103.prem.mail.ac4.yahoo.com with SMTP; 26 Jul 2011 16:57:49 -0700 PDT From: "David Johnston" To: "'Tom Lane'" Cc: References: <201107262228.p6QMSj33073313@wwwmaster.postgresql.org> <19689.1311723714@sss.pgh.pa.us> In-Reply-To: <19689.1311723714@sss.pgh.pa.us> Subject: Re: BUG #6131: Query Returning Incorrect Results Date: Tue, 26 Jul 2011 19:57:42 -0400 Message-ID: <00db01cc4bef$cf1a0e40$6d4e2ac0$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQJs4hqP4MYBgD6YoODxISQdhrgXzgH5DgwKk65RlZA= Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.089 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-1.191, UNPARSEABLE_RELAY=0.001 X-Spam-Level: X-Archive-Number: 201107/183 X-Sequence-Number: 30795 -----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" 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.