From: the6campbells <the6campbells@gmail.com>
To: Bernd Nawothnig <Bernd.Nawothnig@t-online.de>
Cc: Little, Douglas <DOUGLAS.LITTLE@orbitz.com>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: how to: refer to select list calculations other places in the calculations.
Date: Fri, 6 Nov 2009 14:45:15 -0500
Message-ID: <22431f1b0911061145o39013cfem8d4e7a390f9a9ea@mail.gmail.com> (raw)
In-Reply-To: <20091031211106.GA9238@miraculix>
References: <A434C531E37AD442815608A769550D80590432A1BC@EGEXCMB01.oww.root.lcl>
<20091031211106.GA9238@miraculix>
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
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: the6campbells@gmail.com, Bernd.Nawothnig@t-online.de, DOUGLAS.LITTLE@orbitz.com
Subject: Re: how to: refer to select list calculations other places in the calculations.
In-Reply-To: <22431f1b0911061145o39013cfem8d4e7a390f9a9ea@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox