Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 2D64D175B7F0 for ; Wed, 28 Mar 2012 11:02:02 -0300 (ADT) Received: from hub.ringways.co.uk ([77.86.27.30] helo=mail.ringways.co.uk) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SCtRl-0007tB-Aj for pgsql-sql@postgresql.org; Wed, 28 Mar 2012 14:02:01 +0000 Received: from localhost ([127.0.0.1] helo=mail.ringways.co.uk) by mail.ringways.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1SCtRS-0000Vp-Mq for pgsql-sql@postgresql.org; Wed, 28 Mar 2012 15:01:40 +0100 Received: from eddie.ringways.co.uk ([10.1.1.115] helo=eddie.ringways.co.uk) by mail.ringways.co.uk with ESMTP id qF1ZL40c13777; Wed, 28 Mar 2012 15:01:35 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: "pgsql-sql@postgresql.org" Subject: Wrong output from union Date: Wed, 28 Mar 2012 15:01:38 +0100 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201203281501.38835.gary.stainburn@ringways.co.uk> X-SpamTest-Envelope-From: gary.stainburn@ringways.co.uk X-SpamTest-Info: Profiles 20401 [Mar 31 2011] X-SpamTest-Info: {TO: suspicious real name} X-SpamTest-Method: none X-SpamTest-Rate: 10 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0285], KAS30/SDK/Release X-Anti-Virus: Kaspersky Mail Gateway, version: 5.6.28/RELEASE, bases: 20110331T110535 #5151353, check: 20120328 clean X-Spam-Score: -51.5 (---------------------------------------------------) X-Spam-Report: Spam detection software, running on the system "ollie.ringways.co.uk", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see Gary Stainburn for details. Content preview: Hi folks. I have two selects which in themselves report what they should. However, when I run a union to combine their outputs (to then feed a select/count) lines disappear. Below are the two seperate selects, followed by the untion in which duplicate rows are lost. I'm using Postgresql 8.3.3-2 RPMs on a Fedora 9 system. [...] Content analysis details: (-51.5 points, 15.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -50 ALL_TRUSTED Passed through trusted hosts only via SMTP -2.6 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000] 1.0 RING_SAFE RING_SAFE 0.1 AWL AWL: From: address is in the auto white-list X-Pg-Spam-Score: -1.4 (-) X-Archive-Number: 201203/81 X-Sequence-Number: 36476 Hi folks. I have two selects which in themselves report what they should. However, when I run a union to combine their outputs (to then feed a select/count) lines disappear. Below are the two seperate selects, followed by the untion in which duplicate rows are lost. I'm using Postgresql 8.3.3-2 RPMs on a Fedora 9 system. Can anyone tell me why it is happening and how to fix it. Ta. users=# select r_u_id || ':' ||r_deadline as key from requests where r_u_id is not NULL and r_deadline>='2012-03-26' and r_deadline <= ('2012-03-26'::date + '7 days'::interval); key --------------- 25:2012-03-28 25:2012-03-28 25:2012-03-28 25:2012-03-30 25:2012-03-29 25:2012-03-27 (6 rows) users=# select u_id || ':' || rm_timestamp::date as key from request_reminders where u_id is not null and rm_timestamp>='2012-03-26' and rm_timestamp <= ('2012-03-26'::date + '7 days'::interval); key ----- (0 rows) users=# select r_u_id || ':' ||r_deadline as key from requests where r_u_id is not NULL and r_deadline>='2012-03-26' and r_deadline <= ('2012-03-26'::date + '7 days'::interval) union select u_id || ':' || rm_timestamp::date as key from request_reminders where u_id is not null and rm_timestamp>='2012-03-26' and rm_timestamp <= ('2012-03-26'::date + '7 days'::interval); key --------------- 25:2012-03-27 25:2012-03-28 25:2012-03-29 25:2012-03-30 (4 rows) users=# -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk