pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedhow to: refer to select list calculations other places in the calculations.
4+ messages / 4 participants
[nested] [flat]
* how to: refer to select list calculations other places in the calculations.
@ 2009-09-09 13:27 Little, Douglas <DOUGLAS.LITTLE@orbitz.com>
0 siblings, 2 replies; 4+ messages in thread
From: Little, Douglas @ 2009-09-09 13:27 UTC (permalink / raw)
To: pgsql-sql
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<mailto:Douglas.Little@orbitz.com>
[cid:image002.jpg@01CA3127.61E69F30] orbitz.com<http://www.orbitz.com/; | ebookers.com<http://www.ebookers.com/; | hotelclub.com<http://www.hotelclub.com/; | cheaptickets.com<http://www.cheaptickets.com/; | ratestogo.com<http://www.ratestogo.com/; | asiahotels.com<http://www.asiahotels.com/;
Attachments:
image002.jpg (image/jpeg, 2.3K) download
view image
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: how to: refer to select list calculations other places in the calculations.
@ 2009-09-10 16:32 Rob Sargent <robjsargent@gmail.com>
parent: Little, Douglas <DOUGLAS.LITTLE@orbitz.com>
1 sibling, 0 replies; 4+ messages in thread
From: Rob Sargent @ 2009-09-10 16:32 UTC (permalink / raw)
To: Little, Douglas <DOUGLAS.LITTLE@orbitz.com>; pgsql-sql
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* <mailto:Douglas.Little@orbitz.com>**__
>>
>> orbitz.com <http://www.orbitz.com/; | ebookers.com
>> <http://www.ebookers.com/; | hotelclub.com <http://www.hotelclub.com/;
>> | cheaptickets.com <http://www.cheaptickets.com/; | ratestogo.com
>> <http://www.ratestogo.com/; | asiahotels.com <http://www.asiahotels.com/;
>>
>>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: how to: refer to select list calculations other places in the calculations.
@ 2009-10-31 21:11 Bernd Nawothnig <Bernd.Nawothnig@t-online.de>
parent: Little, Douglas <DOUGLAS.LITTLE@orbitz.com>
1 sibling, 1 reply; 4+ messages in thread
From: Bernd.Nawothnig@t-online.de @ 2009-10-31 21:11 UTC (permalink / raw)
To: Little, Douglas <DOUGLAS.LITTLE@orbitz.com>; +Cc: pgsql-sql
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: how to: refer to select list calculations other places in the calculations.
@ 2009-11-06 19:45 the6campbells <the6campbells@gmail.com>
parent: Bernd Nawothnig <Bernd.Nawothnig@t-online.de>
0 siblings, 0 replies; 4+ messages in thread
From: the6campbells @ 2009-11-06 19:45 UTC (permalink / raw)
To: Bernd Nawothnig <Bernd.Nawothnig@t-online.de>; +Cc: Little, Douglas <DOUGLAS.LITTLE@orbitz.com>; pgsql-sql
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
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2009-11-06 19:45 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-09-09 13:27 how to: refer to select list calculations other places in the calculations. Little, Douglas <DOUGLAS.LITTLE@orbitz.com>
2009-09-10 16:32 ` Rob Sargent <robjsargent@gmail.com>
2009-10-31 21:11 ` Bernd Nawothnig <Bernd.Nawothnig@t-online.de>
2009-11-06 19:45 ` the6campbells <the6campbells@gmail.com>
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