Search Postgresql Archives

Re: Column alias in where clause?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martijn van Oosterhout <kleptog@xxxxxxxxx> writes:
> You can't. Conceptually, the result of the SELECT is not visible until
> *after* the WHERE clause has executed, so having the where clause
> depend on the select won't work.

It's not only conceptual.  Consider

	SELECT 1/x FROM mytab WHERE x <> 0;

You'd be unhappy if this query failed with a divide-by-zero error
(and it would be a violation of the SQL spec, too).  So per spec,
the SELECT list must not be evaluated until after WHERE completes,
and that's why it's not reasonable for WHERE to refer to the
SELECT list.

(Now, we've kinda broken this rule by allowing GROUP BY to refer
to SELECT items, but that's a matter for another discussion.)

			regards, tom lane


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux