Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D4524633468 for ; Fri, 6 Nov 2009 15:45:28 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 54054-02 for ; Fri, 6 Nov 2009 19:45:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f213.google.com (mail-bw0-f213.google.com [209.85.218.213]) by mail.postgresql.org (Postfix) with ESMTP id A0187632DAF for ; Fri, 6 Nov 2009 15:45:17 -0400 (AST) Received: by bwz5 with SMTP id 5so1577791bwz.3 for ; Fri, 06 Nov 2009 11:45:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=6BWIdeLqDUu2Lhu5wenAXE4C5tPZ5f7TOShOZVCQulY=; b=sX17bjTzOL5y6uf4WckeRDg5GlMX7OJG412GcnEuh11VTn+8oiEoxyB2DqeAa/yRas l8JAopdcMwai1Yl+VemPow7JNEvZTO8pQrxeIZAUm62KrdAHrOOkLsAxDdlVBozZDFl5 Jy2oE1zFce/h38IuvH7egMjYYJrKpBYOjoVLU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=yIMqU3y42uztsfVKE5KcXLSFc7ESE7NzLN0mZ0Fx8a8hKBLU/bl21T2NwxxDU7oar5 njckbVWZ2Ve4fks3YS8lXI0MFeF2yItyWV/UnPFsqFSx92GI1eXENVWZl0ypu8nynyY2 KigNokFqQkUCUmMP5xZvs/0/9tZBYmTMrtEYU= MIME-Version: 1.0 Received: by 10.204.15.3 with SMTP id i3mr5054717bka.71.1257536715385; Fri, 06 Nov 2009 11:45:15 -0800 (PST) In-Reply-To: <20091031211106.GA9238@miraculix> References: <20091031211106.GA9238@miraculix> Date: Fri, 6 Nov 2009 14:45:15 -0500 Message-ID: <22431f1b0911061145o39013cfem8d4e7a390f9a9ea@mail.gmail.com> Subject: Re: how to: refer to select list calculations other places in the calculations. From: the6campbells To: Bernd Nawothnig Cc: "Little, Douglas" , "pgsql-sql@postgresql.org" Content-Type: multipart/alternative; boundary=00032555a0be366d5f0477b91523 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.114 tagged_above=-10 required=5 tests=AWL=0.484, BAYES_00=-2.599, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200911/33 X-Sequence-Number: 33384 --00032555a0be366d5f0477b91523 Content-Type: text/plain; charset=ISO-8859-1 SQL (unlike MDX) does not allow you to define an expressions and reference it elsewhere in the same block by name. As suggested, a hand written or auto-generated statement can try to refactor the statement by pushing things into a derived table and the outer blocks refer to the projected item names. Not only can this make the SQL more readable it can assist some vendors who internally may not do a great job of common expression factoring. This is one reason why common table expressions are used. For example, if you are in report studio, you can copy the data items into another Bi-Query which you reference from the query that consumes it. On Sat, Oct 31, 2009 at 4:11 PM, Bernd Nawothnig < Bernd.Nawothnig@t-online.de> wrote: > On Wed, Sep 09, 2009 at 08:27:35AM -0500, Little, Douglas wrote: > > > 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? > > I use nested subqueries and do the renaming of calculated columns in the > innermost queries in such cases. > > > > > Bernd > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > --00032555a0be366d5f0477b91523 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
SQL (unlike MDX) does not allow you to define an expressions and refer= ence it elsewhere in the same block by name. As suggested, a hand written o= r auto-generated statement can try to refactor the statement by pushing thi= ngs into a derived table and the outer blocks refer to the projected item n= ames. Not only can this make the SQL more readable it can assist some vendo= rs who internally may not do a great job of common expression factoring. Th= is is one reason why common table expressions are used.
=A0
For example, if you are in report studio, you can copy the data items = into another Bi-Query which you reference from the query that consumes it. =


=A0
On Sat, Oct 31, 2009 at 4:11 PM, Bernd Nawothnig= <Bernd= .Nawothnig@t-online.de> wrote:
On Wed, Sep 09, 2009 at 08:27:35= AM -0500, Little, Douglas wrote:

> I have very complex sql (gener= ated 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?

I use nest= ed subqueries and do the renaming of calculated columns in the
innermost= queries in such cases.




Bernd

--
Sent via pgsql-s= ql mailing list (pgsql-sql@post= gresql.org)
To make changes to your subscription:
http://www.post= gresql.org/mailpref/pgsql-sql

--00032555a0be366d5f0477b91523--