Subselect AS and Where clause

From: Uwe Schroeder <uwe(at)oss4u(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Subselect AS and Where clause
Date: 2011-01-26 07:34:36
Message-ID: 201101252334.37436.uwe@oss4u.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Google being useless tonight - now that's new :-)

What I'm trying to do is the following and I'm certain there is a simple
solution which eludes me:

I have a query like this:

SELECT a,b,c, (select problem from other_table where id=a) as problem FROM
mytable WHERE a=1

So far so good. Actually "problem" always resolves to one record, so it's not
the "multiple records returned" problem.

What I try to do is this:

SELECT a,b,c, (select problem from other_table where id=a) as problem FROM
mytable WHERE a=1 and problem = 3

see the "problem=3" part in the where clause? The error I get is

SQLError: (ProgrammingError) column "problem" does not exist

Do I miss something? Shouldn't the "as" assignment make this virtual column
available to the where clause? I think this should work and I know it works if
I'd make a view out of the query. However, the query is built dynamically, so
turning it into a view isn't really an option.

Any pointer will be greatly appreciated.

Uwe

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Lelarge 2011-01-26 08:06:36 Re: Install Pgadmin3 1.12 on ubuntu 10.4 lucid client without postgresql server install
Previous Message Gary Chambers 2011-01-26 00:10:50 Re: Moving from SQL Anywhere to PostGres - First Time