Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 6D2E113C6999 for ; Fri, 4 May 2012 10:04:44 -0300 (ADT) Received: from plane.gmane.org ([80.91.229.3]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SQIBW-0005AL-RX for pgsql-sql@postgresql.org; Fri, 04 May 2012 13:04:42 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SQIBG-0003rR-Iz for pgsql-sql@postgresql.org; Fri, 04 May 2012 15:04:18 +0200 Received: from 217.110.94.67 ([217.110.94.67]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 04 May 2012 15:04:18 +0200 Received: from spam_eater by 217.110.94.67 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 04 May 2012 15:04:18 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Thomas Kellerer Subject: Re: How change col name during query to use it in where clause Date: Fri, 04 May 2012 15:05:43 +0200 Lines: 19 Message-ID: References: <4FA3AEA9.6010401@marcelruff.info> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 217.110.94.67 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: <4FA3AEA9.6010401@marcelruff.info> X-Pg-Spam-Score: -0.7 (/) X-Archive-Number: 201205/7 X-Sequence-Number: 36555 Marcel Ruff, 04.05.2012 12:25: > Hi, > > is an alias name not usable in the where clause? > > select EXTRACT(day from enddate::TIMESTAMP - old_enddate::TIMESTAMP) AS TAGE from account_h where TAGE>5; > ERROR: column "tage" does not exist > LINE 1: ... TAGE>5 ... You need to wrap the query: select * from ( select EXTRACT(day from enddate::TIMESTAMP - old_enddate::TIMESTAMP) AS TAGE from account_h ) t where TAGE > 5;