Re: [GENERAL] How to use result column names in having cause

2006-03-31 Thread Tom Lane
"chris smith" <[EMAIL PROTECTED]> writes: > I assume it's this way because the standard says so.. Right. From a logical point of view, the HAVING clause has to be evaluated before the output expressions are computed, so it doesn't make any sense to expect the output expressions to be available in

Re: [GENERAL] How to use result column names in having cause

2006-03-31 Thread Stephan Szabo
On Fri, 31 Mar 2006, Andrus wrote: > >> 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 limi

Re: [GENERAL] How to use result column names in having cause

2006-03-31 Thread Robert Treat
On Friday 31 March 2006 08:30, chris smith wrote: > On 3/31/06, Andrus <[EMAIL PROTECTED]> wrote: > > >> 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 na

Re: [GENERAL] How to use result column names in having cause

2006-03-31 Thread chris smith
On 3/31/06, Andrus <[EMAIL PROTECTED]> wrote: > >> 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

Re: [GENERAL] How to use result column names in having cause

2006-03-31 Thread Andrus
Here is my problematic query which runs OK in other DBMS. Only way to run this in Postgres is to duplicate reatasum expression two times in HAVING clause, right ? Andrus. SELECT 'z' as doktyyp, r1.dokumnr, r1.kuluobjekt as objekt, r1.rid2obj, r1.rid3obj, r1.rid4obj, r1.rid5obj,

Re: [GENERAL] How to use result column names in having cause

2006-03-31 Thread Andrus
>> 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': Doc about HAVING

Re: [GENERAL] How to use result column names in having cause

2006-03-31 Thread chris smith
On 3/31/06, Andrus <[EMAIL PROTECTED]> 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 o