Re: Select aliasses in where and other places of the - Mailing list pgsql-general

From Stephan Szabo
Subject Re: Select aliasses in where and other places of the
Date
Msg-id 20030329103833.G12465-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Select aliasses in where and other places of the selectlist?  (Arjen van der Meijden <acm@tweakers.net>)
List pgsql-general
On Sat, 29 Mar 2003, Arjen van der Meijden wrote:

> I know it isn't possible to do queries like:
> SELECT 1 AS c, c + 1 AS d;
>
> Other queries that aren't possible are those:
> SELECT intfield AS a, intfield * intfield AS square FROM tableX WHERE a
> < 10 AND square < 50
>
> Of course, these are bogus examples to simply illustrate my point :)
> But is there a good reason not to support it or is it something like
> "not yet implemented", "not interesting" or "to complex to (easily)
> implement".

For the second, in the theoretical model, where clause entries are
processed before the select list is evaluated.  You don't want to evaluate
the entire select list before testing the where (what if there's an
expensive subselect or function).  You could get around that by only doing
the referenced ones, but you still run into issues if a select list entry
has the same name as a field in one of the from entries (since to be
complient it must be the field not the select list entry afaics). There'd
have to be a good definition and some real gain (for particularly
complicated cases you can use subselect in from to avoid double typing of
the expression so I personally don't think that's good enough alone).


pgsql-general by date:

Previous
From: RobertD.Stewart@mail.state.ky.us
Date:
Subject: functions and triggers
Next
From: Stephan Szabo
Date:
Subject: Re: pg_dump data and foreign keys