Re: can not use the column after rename

From: salah jubeh <s_jubeh(at)yahoo(dot)com>
To: Simon Tokumine <simon(at)vizzuality(dot)com>
Cc: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: can not use the column after rename
Date: 2011-12-21 13:24:11
Message-ID: 1324473851.73274.YahooMailNeo@web161501.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello Simon,

This question was raised up during writing a query where many columns are a result of long mathematical operations, so I thought why not to rename them and use the new names  instead of repeating the same operations

On the row level,  the value of a and b are know, so why we need a temporary table or CTE. Why I can not use it directly  as shown in the example below. why a and b can not be used as aliases for the column names ? I want to know the theoretical reason behind it?

Thanks

CREATE TABLE numbers (
    num1 integer,
    num2 integer
 );

 INSERT INTO numbers values (3,4);

 SELECT num1, num2, num1 + num2 FROM numbers

  SELECT num1 as a, num2 as b, a + b as c FROM number
  SELECT num1 as a, num2 as b, num1 + num2 as c FROM numbers

 

________________________________
From: Simon Tokumine <simon(at)vizzuality(dot)com>
To: salah jubeh <s_jubeh(at)yahoo(dot)com>
Cc: pgsql <pgsql-general(at)postgresql(dot)org>
Sent: Wednesday, December 21, 2011 1:14 PM
Subject: Re: [GENERAL] can not use the column after rename

Hi Salah,

This is equivalent:

WITH numbers AS (SELECT 1 AS a, 2 AS b) SELECT a, b, a+b AS c FROM numbers;

S

On Wed, Dec 21, 2011 at 11:39 AM, salah jubeh <s_jubeh(at)yahoo(dot)com> wrote:

Hello,
>
>
>
>Why I can not do something like this in Postgres.
>
>
>
> SELECT 1 as a , 2 as b , a + b as c ;
>
>
>Regards
>

>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jacques Lamothe 2011-12-21 13:26:40 Cannot connect to 2nd cluster database remotely
Previous Message Simon Tokumine 2011-12-21 12:14:52 Re: can not use the column after rename