Re: Column as result of subtraction of two other columns? - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: Column as result of subtraction of two other columns?
Date
Msg-id 20040716151508.GA2902@wolff.to
Whole thread Raw
In response to Column as result of subtraction of two other columns?  ("Mark Cave-Ayland" <m.cave-ayland@webbased.co.uk>)
Responses Re: Column as result of subtraction of two other columns?
List pgsql-general
On Fri, Jul 16, 2004 at 15:31:33 +0100,
  Mark Cave-Ayland <m.cave-ayland@webbased.co.uk> wrote:
> Hi everyone,
>
> I'm trying to calculate an output column which is the difference of two
> other columns in the query output; the first column is an aggregate of
> items in stock, while the second column is an aggregate of items which
> have been used. The third column should should be the difference of the
> two values so I can then output all three columns in a table.
>
> Unfortunately I can't get this to work at the moment :(. I've simplified
> the query down to the following:
>
> dev=# select 1 as a, 2 as b, (b - a) as c;
> ERROR:  column "b" does not exist
> dev=#
>
> Do I need to create some form of alias so the calculation can see the
> other columns? I am using PostgreSQL 7.4.2 on Linux.

You can't use column aliases in other columns; you need to repeat the
column expressions.

pgsql-general by date:

Previous
From: mmc@maruska.dyndns.org (Michal Maruška)
Date:
Subject: Re: PQftable insufficient for primary key determination
Next
From: Paul Thomas
Date:
Subject: Re: Column as result of subtraction of two other columns?