Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 53FE29FA60A for ; Tue, 7 Nov 2006 19:49:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 50014-10 for ; Tue, 7 Nov 2006 23:49:08 +0000 (UTC) X-Greylist: delayed 23:38:35.445247 by SQLgrey- Received: from resolution.com (unknown [65.18.201.170]) by postgresql.org (Postfix) with ESMTP id 22FD19FA22C for ; Tue, 7 Nov 2006 19:49:07 -0400 (AST) Received: (from resolutio@localhost) by resolution.com (8.12.10/8.11.2) id kA7Nn69h029954 for pgsql-sql@postgresql.org; Tue, 7 Nov 2006 18:49:06 -0500 From: gurkan@resolution.com X-Authentication-Warning: resolution.com: resolutio set sender to gurkan@resolution.com using -f To: pgsql-sql@postgresql.org Subject: Re: converting Informix outer to Postgres Message-ID: <1162943346.45511b720c367@www.resolution.com> Date: Tue, 07 Nov 2006 18:49:06 -0500 (EST) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: IMP/PHP IMAP webmail program 2.2.8 X-Originating-IP: 70.238.208.142 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/103 X-Sequence-Number: 26755 > --- gurkan@resolution.com wrote: > > > Hi all, > > I have been working on this Informix SQL query which has an outer > join. > > I have attached Informix query and my "supposedly" solution to this > query > > but I cannot get the same count. I appreciate for any help. > > Thanks. > > > > --Informix query > > select count(u.id) > > from user u, invention i, inv_contracts ic, inv_milestones im1, > milestonedef mdef1, > > OUTER inv_milestones im2, > > milestonedef mdef2 > > where u.id = i.user_id and > > ic.inv_id = i.id and > > ic.contract_id = mdef1.contract_id and > > im1.inv_id = i.id and > > mdef1.id = im1.milestone_id and > > im1.datesent BETWEEN '2005-05-05' AND '2005-05-10' and > > ic.contract_id = mdef2.contract_id and > > im2.inv_id = i.id and > > mdef2.id = im2.milestone_id and > > im1.datereceived IS NULL > > > > --Postges query > > select count(u.id) > > from dbuser u, inv_contracts ic, inv_milestones im1, milestonedef > mdef1, > > --OUTER inv_milestones im2, > > milestonedef mdef2 LEFT OUTER JOIN inv_milestones im2 ON mdef2.id = > im2.milestone_id > > LEFT OUTER JOIN invention i ON im2.inv_id = i.id > > where u.id = i.user_id and > > ic.inv_id = i.id and > > ic.contract_id = mdef1.contract_id and > > im1.inv_id = i.id and > > mdef1.id = im1.milestone_id and > > im1.datesent BETWEEN '2005-05-05' AND '2005-05-10' and > > ic.contract_id = mdef2.contract_id and > > --im2.inv_id = i.id and --QUERY1 > > --mdef2.id = im2.milestone_id and --QUERY2 > > im1.datereceived IS NULL > > Is there a reason that these two lines are commented out in the > postgresql query? The reason is that once it is converted to postgres (LEFT OUTER), those two query moved into LEFT OUTER JOIN clause. For simplicity; if the Informix query were as; select count(u.id) from user u, OUTER inv_milestones im2, milestonedef mdef2 where mdef2.id = im2.milestone_id --QUERY2 in Postgres it would have been as; select count(u.id) from dbuser u, --OUTER inv_milestones im2, milestonedef mdef2 LEFT OUTER JOIN inv_milestones im2 ON mdef2.id = im2.milestone_id --where --mdef2.id = im2.milestone_id --QUERY2 In original Informix outer query has one OUTER but has two queries(QUERY1,QUERY2). I can test my conversion at one query a time meaning I can do my conversion if there were only QUERY1 or QUERY2. In my test cases they return the same number on count, but I cannot do it for QUERY1 and QUERY2 at the same time. I have done it before for this kind of query but for this case my solution is not working. thanks for help. ------------------------------------------------- This mail sent through IMP: www.resolution.com