Received: from p1.selectacast.net (p1.selectacast.net [64.15.230.162]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f7OJVKf82202 for ; Fri, 24 Aug 2001 15:31:20 -0400 (EDT) (envelope-from jks@selectacast.net) Received: from selectacast.net (IDENT:jks@d1 [64.7.9.58]) by p1.selectacast.net (8.9.3/8.9.3) with ESMTP id PAA07811; Fri, 24 Aug 2001 15:31:15 -0400 Message-ID: <3B86AB82.9040501@selectacast.net> Date: Fri, 24 Aug 2001 15:31:14 -0400 From: Joseph Shraibman Organization: Xtenit, Inc. http://www.xtenit.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.3) Gecko/20010801 X-Accept-Language: en-us MIME-Version: 1.0 To: Stephan Szabo CC: pgsql-sql Subject: Re: WHERE on an alias References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200108/302 X-Sequence-Number: 4548 That was just an example. My code doesn't use group by, it uses a subselect. And I checked and having doesn't work with aliases either. Stephan Szabo wrote: > On Fri, 24 Aug 2001, Joseph Shraibman wrote: > > >>playpen=# select a, sum(b) as dsum from taba where dsum > 5 group by(a); >>ERROR: Attribute 'dsum' not found >> >>Why can we GROUP BY on an alias but not do a WHERE on an alias? I have a subselect that >>explain shows is being run twice if I have to put it in the WHERE clause. >> > > Somewhat unrelated question, are you sure you want where and not having? > IIRC, where is going to select rows before things like the group by > occur, and that doesn't seem to be what you'd want here, right? > -- Joseph Shraibman jks@selectacast.net Increase signal to noise ratio. http://www.targabot.com