Re: Using column aliasses in the same query

From: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Using column aliasses in the same query
Date: 2011-04-17 11:21:49
Message-ID: 201104171321.49747.leif@solumslekt.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sunday 17 April 2011 13:01:45 Robert J.C. Ivens wrote:
> Hi,
>
> I am not sure if there ever was a feature request for using defined column
> aliases in the rest of a query. This would make queries with a lot of
> logic in those aliased columns a lot smaller and this easier to
> write/debug.
>
> I already know you can use the following syntax:
>
> SELECT col1, col2, col3, (col2-col3) as col4 FROM (SELECT col1, (long and
> lots of logic here) as col2, col3 FROM table) s WHERE col2 < aValue
>
> But when you need to use (calculated) values from the actual record and or
> have sub-selects in your main select that also need to use these values
> things get really hairy. I don't know if the SQL specification allows it
> but I know that RDBMS's like Sybase already support this.
>
> Any thoughts?

It's easy to define a view or an SQL function and stash the hairy logic there.

regards, Leif

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert J.C. Ivens 2011-04-17 11:30:48 Re: Using column aliasses in the same query
Previous Message Radosław Smogura 2011-04-17 11:14:15 Re: Howto sort the result of UNION (without modifying its type)?