Re: RFE: Column aliases in WHERE clauses

Поиск
Список
Период
Сортировка
От Steve Haresnape
Тема Re: RFE: Column aliases in WHERE clauses
Дата
Msg-id 505967F1.9010801@creativeintegrity.co.nz
обсуждение исходный текст
Ответ на RFE: Column aliases in WHERE clauses  ("Daniel Serodio (lists)" <daniel.lists@mandic.com.br>)
Ответы Re: RFE: Column aliases in WHERE clauses
Re: RFE: Column aliases in WHERE clauses
Список pgsql-general
Hi There,

I've snipped a piece for the daily digest because I take issue with what's asserted here as a reason for not allowing
aliasesin where clauses. 

<< snip    This isn't just academic nit-picking either, because the SELECT
expressions might not be valid for rows that don't pass WHERE etc.
Consider
     SELECT 1/x AS inverse FROM data WHERE x <> 0;
The implementation *must* apply WHERE before computing the SELECT
expressions, or it'll get zero-divide failures that should not happen.     end snip>>

Irrespective of whether the standard prohibits aliases in where clauses, the reasoning here is irrelevant to the
discussionat hand. 

If I say:
     SELECT 1/x AS inverse FROM data WHERE x <> 0 or inverse > 0.5 (for arguments sake) (in a SQL dialect that supports
it)
then I must expect inverse to be evaluated for every row, exactly as if I said:
     SELECT 1/x AS inverse FROM data WHERE x <> 0 or 1/x > 0.5

It's surely not the role of the standard to protect us from the consequences of our own folly.

Since some dialects support the idiom and others don't there can't be any compelling reason to withhold support. It's
reallya matter of style. 
For my money the DRY style is better.

--
Steve Haresnape
Creative Integrity Ltd



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

Предыдущее
От: Edson Richter
Дата:
Сообщение: Re: Change key primary for key foreign
Следующее
От: Gabriele Bartolini
Дата:
Сообщение: Re: foreign key from array element