Re: Using column aliasses in the same query

Поиск
Список
Период
Сортировка
От Robert J.C. Ivens
Тема Re: Using column aliasses in the same query
Дата
Msg-id D4619301-320C-40E6-961F-25DE26785E1B@roclasi.com
обсуждение исходный текст
Ответ на Re: Using column aliasses in the same query  (Leif Biberg Kristensen <leif@solumslekt.org>)
Ответы Re: Using column aliasses in the same query  (Cédric Villemain <cedric.villemain.debian@gmail.com>)
Re: Using column aliasses in the same query  (pasman pasmański <pasman.p@gmail.com>)
Список pgsql-general
On 17 apr 2011, at 13:21, Leif Biberg Kristensen wrote:

> 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

True, but that is essentially the same thing as the example query I gave.
There are plenty of cases where this approach is not workable.

Cheers,
Robert


В списке pgsql-general по дате отправления:

Предыдущее
От: Leif Biberg Kristensen
Дата:
Сообщение: Re: Using column aliasses in the same query
Следующее
От: Cédric Villemain
Дата:
Сообщение: Re: Using column aliasses in the same query