Re: How to use result column names in having cause

From: "chris smith" <dmagick(at)gmail(dot)com>
To: Andrus <eetasoft(at)online(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to use result column names in having cause
Date: 2006-03-31 12:18:47
Message-ID: 3c1395330603310418p6998e578n6e5c1e728c4aca91@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/31/06, Andrus <eetasoft(at)online(dot)ee> wrote:
> CREATE TEMP TABLE foo( bar integer );
>
> SELECT 123 AS x
> FROM foo
> GROUP BY 1
> HAVING x> AVG(bar)
>
> causes
>
> ERROR: column "x" does not exist
>
> Why ? How to make this working ?
>
> In real application I have long expression instead of 123 and do'nt want
> repeat this expression in HAVING clause.

You have to repeat the expression. "AS" changes the output name, it
can't be used either in the where clause or any other limiting factor
like 'having':

test=# create table t1(a int);
test=# insert into t1(a) values (1);
test=# SELECT a AS x from t1 where x=1;
ERROR: column "x" does not exist

--
Postgresql & php tutorials
http://www.designmagick.com/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message deepak pal 2006-03-31 12:38:55 how to use pg_dump in windows xp
Previous Message Andrus 2006-03-31 12:03:25 How to use result column names in having cause