X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 0B85ED1D8C8 for ; Mon, 12 Jan 2004 06:28:31 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 91266-05 for ; Mon, 12 Jan 2004 02:28:00 -0400 (AST) Received: from serwer.skawsoft.com.pl (skawina.eu.org [80.48.213.66]) by svr1.postgresql.org (Postfix) with ESMTP id 49F87D1D575 for ; Mon, 12 Jan 2004 02:27:55 -0400 (AST) Received: from klaster.net (backbone.zab.citynet.pl [212.244.6.69]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 84FF42B3EB; Mon, 12 Jan 2004 07:26:54 +0100 (CET) Message-ID: <40023E79.10705@klaster.net> Date: Mon, 12 Jan 2004 07:28:09 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.6b) Gecko/20031208 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Robert Creager Cc: PGSQL Subject: Re: Problem with NOT IN portion of query. References: <20040111210454.4ee900ae.Robert_Creager@LogicalChaos.org> In-Reply-To: <20040111210454.4ee900ae.Robert_Creager@LogicalChaos.org> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/89 X-Sequence-Number: 16482 Dnia 2004-01-12 05:04, Użytkownik Robert Creager napisał: > Hey All, > > Probably doing something stupid, and I'm too tired to see what. The query I'm > trying to execute is: > > SELECT date_trunc( 'hour', "when" )::timestamp AS > period FROM readings WHERE period NOT IN (SELECT "time" FROM > hour.summary_period) GROUP BY period ORDER BY period; > > Where the table definitions are: > > CREATE TABLE readings ( "when" TIMESTAMP DEFAULT now() NOT NULL PRIMARY KEY ); > CREATE SCHEMA hour; > CREATE TABLE hour.summary_period ( "time" TIMESTAMP NOT NULL ); > > The error is: > > ERROR: column "period" does not exist > > When I remove the NOT IN (and associated WHERE), the query works fine. Your problem has nothing to "NOT IN". Your query works fine, when you remove column alias from WHERE clause - it's beacause WHERE clause is executed *before* data output (and before column aliases). You can still use column aliases in "GROUP BY" and "ORDER BY". Regards, Tomasz Myrta