Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id E46A7634A15 for ; Thu, 10 Sep 2009 13:32:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 62352-09 for ; Thu, 10 Sep 2009 16:32:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f191.google.com (mail-pz0-f191.google.com [209.85.222.191]) by mail.postgresql.org (Postfix) with ESMTP id DA05163412E for ; Thu, 10 Sep 2009 13:32:45 -0300 (ADT) Received: by pzk29 with SMTP id 29so213423pzk.14 for ; Thu, 10 Sep 2009 09:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=7GLjXdgXsyujiDt1Sm+aRlpihRBwYLOc7gOQd0EkK9k=; b=OUADD7RIbOyQYXcSdUprmhyVg/+g+e8aWklfLAGlRCiwb+US2rqD9udAUWcEEigDrf kcjvQhiaYW28oIiNxoCmc07s9AHkgS1CdXTxlatWleWOh9r77WuytZeYEDBYzEshnrK/ TVcf7ihmIhqIewRvf8LKp4BuAlcyiAein4DrU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=pKNxLy6rdcUhn/dioLK9RWnJspbHSNekvG2BKJpXKYZZ8h+lDpXAZs9m7v7FpdB+T9 bW6K02+vSWQCyBvUGt8IOnC19eNQ3G3zjWEAKz0S8TDbVr3jSB/sVK1kmiU5XKRlAs+L PJ9vdqTzhw3qwrMNOBeR4Oyi8LprpGUFLv5FM= Received: by 10.114.253.13 with SMTP id a13mr3251987wai.13.1252600363737; Thu, 10 Sep 2009 09:32:43 -0700 (PDT) Received: from ?192.168.1.77? ([66.183.181.157]) by mx.google.com with ESMTPS id 20sm1847925pzk.13.2009.09.10.09.32.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 10 Sep 2009 09:32:43 -0700 (PDT) Message-ID: <4AA92A28.1060902@gmail.com> Date: Thu, 10 Sep 2009 10:32:40 -0600 From: Rob Sargent User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: "Little, Douglas" , "pgsql-sql@postgresql.org" Subject: Re: how to: refer to select list calculations other places in the calculations. References: <4AA88783.1040204@gmail.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.759 tagged_above=-10 required=5 tests=BAYES_20=-0.74, URIBL_SBL=1.499 X-Spam-Level: X-Archive-Number: 200909/43 X-Sequence-Number: 33108 I might do the substitution, analyse the query and hope to break it up. Can it possibly be optimal? Little, Douglas wrote: > Hi Rob, > Thanks for the response. > Repeating the base calculation will work but the calculations are stunningly complex and long. Repeating them will undoubtly increase editing errors and maintenance problems. > > Wish I had a sample to post. Last query I analyzed was approx 10k lines and printed to over 50 pages. Yes, it was a single query. I'm amazed that cognos would generate. Basically they generate a pivoted cross-tab from sql. > > Thanks > Doug > > > > > -----Original Message----- > From: Rob Sargent [mailto:robjsargent@gmail.com] > Sent: Wednesday, September 09, 2009 11:59 PM > To: Little, Douglas > Subject: Re: [SQL] how to: refer to select list calculations other places in the calculations. > > Would reverting to the base columns work? > > select a, b, a+b as c, (a+b)*d, (a+b)*f etc. > > Little, Douglas wrote: > >> Hi, >> >> I have very complex sql (generated by cognos) I'm porting from >> Teradata that basically uses column alias in the calculated columns. >> >> Is there any way to do this type of thing in Psql? >> >> Essentially I need to do is refer to a calculated column later in the >> select list (but far more complex - like 50 pages printed out) >> >> sel a,b,a+b as c, c*d, c*f, c*g, c*h, c*I, c*j, c*k,...... --- where c is >> a calculated column used in other calculations. >> >> from .... >> >> **Doug Little** >> >> Sr. Data Warehouse Architect | Enterprise Data Management | Orbitz >> Worldwide >> >> 500 W. Madison, Suite 1000 Chicago IL 60661| Office 312.260.2588 | Fax >> 312.894.5164 | Cell 847-997-5741 >> >> >> ***Douglas.Little@orbitz.com* **__ >> >> orbitz.com | ebookers.com >> | hotelclub.com >> | cheaptickets.com | ratestogo.com >> | asiahotels.com >> >>