Re: Problem with NOT IN portion of query.

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
To: Robert Creager <Robert_Creager(at)LogicalChaos(dot)org>
Cc: PGSQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Problem with NOT IN portion of query.
Date: 2004-01-12 06:28:09
Message-ID: 40023E79.10705@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message azwa 2004-01-12 09:12:11 Insert into
Previous Message katarn 2004-01-12 05:51:17 Unique key field or serverl fks ?