Обсуждение: Reusing columns in SELECT list

Поиск
Список
Период
Сортировка

Reusing columns in SELECT list

От
Andre Majorel
Дата:
Hello all.

Is there a way to reuse in the SELECT list columns defined earlier
in it ? With PostgreSQL 8.0, I couldn't manage to do it :

  => CREATE table a (x int);
  CREATE TABLE
  => CREATE table b (y int);
  CREATE TABLE
  => SELECT x * y AS xy, xy + xy AS twoxy FROM a, b;
  ERROR:  column "xy" does not exist

--
André Majorel <URL:http://www.teaser.fr/~amajorel/>
Do not use this account for regular correspondence.
See the URL above for contact information.

Re: Reusing columns in SELECT list

От
Tom Lane
Дата:
Andre Majorel <aym-lqsgp@teaser.fr> writes:
> Is there a way to reuse in the SELECT list columns defined earlier
> in it ?

No.

You can use multiple levels of select:

select xy, xy + xy from (select x * y as xy from a,b) ss;

but this is not likely to save any computation, just typing.

            regards, tom lane