Re: Select aliasses in where and other places of the selectlist?
От | Tom Lane |
---|---|
Тема | Re: Select aliasses in where and other places of the selectlist? |
Дата | |
Msg-id | 884.1048979094@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Select aliasses in where and other places of the selectlist? (Arjen van der Meijden <acm@tweakers.net>) |
Список | pgsql-general |
Arjen van der Meijden <acm@tweakers.net> writes: > I know it isn't possible to do queries like: > SELECT 1 AS c, c + 1 AS d; > 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". It's not supported because it would violate the SQL spec. The spec is perfectly clear about the scope of names, and a SELECT's output column names aren't in scope anywhere in the SELECT itself (except in ORDER BY). If we treated them as if they were, we'd break queries that rely on the spec-mandated scoping --- think about cases where the output column names happen to conflict with column names available from the input tables. You can however use a sub-select: SELECT * FROM (SELECT intfield AS a, intfield * intfield AS square FROM tableX) AS ss WHERE a < 10 AND square < 50 Note that it'd be unwise to assume this technique will eliminate double evaluations of expressions. But it saves having to type them more than once, at least. regards, tom lane
В списке pgsql-general по дате отправления: